/
changePassword.php
81 lines (67 loc) · 2.18 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
71
72
73
74
75
76
77
78
79
80
81
<?php include $_SERVER['DOCUMENT_ROOT'].'/includes/header.php'; ?>
<?php
$user = new User();
if(!$user->isLoggedIn()){
Redirect::to('/');
}
if(Input::exists()){
if(Token::check(Input::get('token'))){
$validate = new Validate();
$validation = $validate->check($_POST, array(
'password' => array(
'required' => true,
'min' => 8
),
'newPassword' => array(
'required' => true,
'min' => 8
),
'newPasswordConfirm' => array(
'required' => true,
'matches' => 'newPassword'
)
));
if($validation->passed()){
if(Hash::make(Input::get('password'), $user->data()->Salt) !== $user->data()->Password){
echo 'Your current password is wrong.';
}else{
$salt = Hash::salt(32);
try{
$user->update(array(
'Password' => Hash::make(Input::get('newPassword'), $salt),
'Salt' => $salt,
));
Session::flash('home', 'Your password has been updated.');
Redirect::to('/');
}catch(Exception $e){
die($e->getMessage());
}
}
}else{
foreach($validation->errors() as $error){
echo $error, '<br />';
}
}
}
}
?>
<div class="col-md-6 col-md-offset-3">
<form action="" method="POST">
<h2 class="form-signin-heading">Update password</h2>
<div class="form-group">
<label for="inputCurrentPassword" class="sr-only">Current Password</label>
<input type="password" id="inputCurrentPassword" class="form-control" name="password" placeholder="Current Password" required>
</div>
<div class="form-group">
<label for="inputNewPassword" class="sr-only">New Password</label>
<input type="password" id="inputNewPassword" class="form-control" name="newPassword" placeholder="New Password" required>
</div>
<div class="form-group">
<label for="inputNewPasswordConfirm" class="sr-only">Confirm New Password</label>
<input type="password" id="inputNewPasswordConfirm" class="form-control" name="newPasswordConfirm" placeholder="Confirm New Password" required>
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<button class="btn btn-lg btn-primary btn-block" type="submit">Update</button>
</form>
</div>
<?php include $_SERVER['DOCUMENT_ROOT'].'/includes/footer.php';?>