-
Notifications
You must be signed in to change notification settings - Fork 0
/
changepassword.php
72 lines (68 loc) · 2.75 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
<?php
require_once 'core/init.php';
$user = new User();
if (!$user->isLoggedIn()) {
Redirect::to('index.php');
}
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'current_password' => array(
'required' => true,
'min' => 6
),
'new_password' => array(
'required' => true,
'min' => 6
),
'new_confirm-password' => array(
'required' => true,
'min' => 6,
'matches' => 'new_password'
)
));
}
if ($validate->passed()) {
if (!Hash::isValidPassword(Input::get('current_password'), $user->data()->password)) {
Session::flash('error', 'Your current password is wrong.');
} else {
$user->update(array(
'password' => Hash::encryptPassword(Input::get('new_password'))
));
Session::flash('success', 'Your password has been changed!');
Redirect::to("index.php?user=" . $username);
}
} else {
$errors = $validate->errors();
}
}
?>
<div class="container">
<form action="" method="post">
<div class="form-group">
<input id="current_password" type="password" name="current_password" id="current_password" class="form-control" placeholder="Current Password" required>
<span toggle="#current_password" class="fa fa-fw fa-eye field-icon toggle-password"></span>
</div>
<div class="form-group">
<input id="new_password" type="password" name="new_password" id="new_password" class="form-control" placeholder="New Password" required>
<span toggle="#new_password" class="fa fa-fw fa-eye field-icon toggle-password"></span>
</div>
<div class="form-group">
<input type="password" name="new_confirm-password" id="new_confirm-password" class="form-control" placeholder="Confirm Password" required>
</div>
<div class="form-group">
<input type="hidden" name="token" id="token" value="<?php echo escape(Token::generate()); ?>">
<input type="submit" class="form-control btn btn-primary submit px-3" value="Change Password">
</div>
<?php if (isset($errors)) : ?>
<div class="alert p-1 mt-1">
<?php foreach ($errors as $error) : ?>
<div class="alert-danger p-2 mb-1"><?php echo $error; ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</form>
</div>
</body>
</html>