-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangepassword.php
70 lines (61 loc) · 1.76 KB
/
changepassword.php
1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once 'core/init.php';
ob_start();
require_once 'includes/header.php';
if(Session::exists('update')){
echo "<div id='update_error'>".Session::flash('update')."</div>";
}
$user = new User();
if(!$user->isLoggedIn()){
Redirect::to('login.php');
}
if(Input::exists()){
if(Token::check(Input::get('token'))){
$validate = new Validate();
$validation = $validate->check($_POST, array(
'password_current' => array(
'required' => true,
'min' => 6
),
'password_new' => array(
'required' => true,
'min' => 6
),
'password_new_again' => array(
'required' => true,
'min' => 6,
'matches' => 'password_new'
)
));
if($validation->passed()){
if(Hash::make(Input::get('password_current'), $user->data()->salt) !== $user->data()->password){
echo "<div id='update_error'>Your current password is wrong..</div>";
} else {
$salt = Hash::salt(32);
$user->update(array(
'password' => Hash::make(Input::get('password_new'), $salt),
'salt' => $salt
));
Session::flash('update', 'Your password has been changed successfully');
Redirect::to('changepassword.php');
}
} else {
echo "<div id='password_error'>Error updating password..</div>";
}
}
}
require_once 'includes/nav.php';
?>
<div id="profile_cont">
<form action="" method="post">
<input type="password" name="password_current" placeholder="Current Password" />
<input type="password" name="password_new" placeholder="New Password" />
<input type="password" name="password_new_again" placeholder="Re-enter New Password" />
<input type="submit" value="Update Password" />
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>" />
</form>
</div>
<?php
require_once 'includes/footer.php';
ob_end_flush();
?>