Automad
 All Classes Functions Variables Pages
change_password.php
1 <?php
2 /*
3  * ....
4  * .: '':.
5  * :::: ':..
6  * ::. ''..
7  * .:'.. ..':.:::' . :. '':.
8  * :. '' '' '. ::::.. ..:
9  * ::::. ..':.. .'''::::: .
10  * :::::::.. '..:::: :. :::: :
11  * ::'':::::::. ':::.'':.:::: :
12  * :.. ''::::::....': '':: :
13  * :::::. '::::: : .. '' .
14  * .''::::::::... ':::.'' ..'' :.''''.
15  * :..:::''::::: :::::...:'' :..:
16  * ::::::. ':::: :::::::: ..:: .
17  * ::::::::.:::: :::::::: :'':.:: .''
18  * ::: '::::::::.' ''::::: :.' '': :
19  * ::: :::::::::..' :::: ::...' .
20  * ::: .:::::::::: :::: :::: .:'
21  * '::' ''::::::: :::: : :: :
22  * ':::: :::: :'' .:
23  * :::: :::: ..''
24  * :::: ..:::: .:''
25  * '''' '''''
26  *
27  *
28  * AUTOMAD
29  *
30  * Copyright (c) 2014 by Marc Anton Dahmen
31  * http://marcdahmen.de
32  *
33  * Licensed under the MIT license.
34  * http://automad.org/license
35  */
36 
37 
38 defined('AUTOMAD') or die('Direct access not permitted!');
39 
40 
41 /*
42  * Change password of currently logged in user.
43  */
44 
45 
46 $output = array();
47 
48 
49 if (isset($_POST['current-password']) && $_POST['current-password'] && isset($_POST['new-password1']) && $_POST['new-password1'] && isset($_POST['new-password2']) && $_POST['new-password2']) {
50 
51  if ($_POST['new-password1'] == $_POST['new-password2']) {
52 
53  if ($_POST['current-password'] != $_POST['new-password1']) {
54 
55  // Get all accounts from file.
56  $accounts = $this->accountsGetArray();
57 
58  if ($this->passwordVerified($_POST['current-password'], $accounts[$this->user()])) {
59 
60  // Change entry for current user with accounts array.
61  $accounts[$this->user()] = $this->passwordHash($_POST['new-password1']);
62 
63  // Write array with all accounts back to file.
64  if ($this->accountsSaveArray($accounts)) {
65 
66  $output['success'] = $this->tb['success_password_changed'];
67 
68  } else {
69 
70  $output['error'] = $this->tb['error_permission'] . '<p>' . AM_FILE_ACCOUNTS . '</p>';
71 
72  }
73 
74  } else {
75 
76  $output['error'] = $this->tb['error_form'];
77 
78  }
79 
80  } else {
81 
82  $output['error'] = $this->tb['error_form'];;
83 
84  }
85 
86  } else {
87 
88  $output['error'] = $this->tb['error_form'];
89 
90  }
91 
92 } else {
93 
94  $output['error'] = $this->tb['error_form'];
95 
96 }
97 
98 
99 echo json_encode($output);
100 
101 
102 ?>