/
changepassword.php
151 lines (131 loc) · 6.11 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Created by Chris on 9/29/2014 3:53 PM.
*/
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_password_again' => array(
'required' => true,
'min' => 6,
'matches' => 'new_password'
)
));
if ($validate->passed()) {
if (Hash::make(Input::get('current_password'), $user->data()->salt) !== $user->data()->password) {
Session::flash('error', 'Your current password is incorrect.');
Redirect::to('changepassword.php');
} else {
$salt = Hash::salt(32);
$user->update(array(
'password' => Hash::make(Input::get('new_password'), $salt),
'salt' => $salt
));
Session::flash('success', 'Your password has been changed!');
Redirect::to('index.php');
}
} else {
foreach ($validate->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OOP Login/Register</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="css/material.css" rel="stylesheet">
<link href="css/ripples.css" rel="stylesheet">
<link href="css/material-wfont.min.css" rel="stylesheet">
<link href="css/icons-material-design.css" rel="stylesheet">
<link href="css/snackbar.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<?php require_once 'header.php'; ?>
</head>
<body>
<div class="container">
<div class="row vertical-offset-100">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Change Password</h3>
</div>
<div class="panel-body">
<?php
//Alert Boxes
if(Session::exists('success')) {
echo '<div class="bs-component" style="padding: "><div class="alert alert-dismissable alert-success"><button type="button" class="close" data-dismiss="alert">×</button>' . Session::flash('success'). '</div></div>';
} else {
if (Session::exists('error')) {
echo '<div class="bs-component" style="padding: "><div class="alert alert-dismissable alert-danger"><button type="button" class="close" data-dismiss="alert">×</button>' . Session::flash('error') . '</div></div>';
} else {
if (Session::exists('info')) {
echo '<div class="bs-component" style="padding: "><div class="alert alert-dismissable alert-info"><button type="button" class="close" data-dismiss="alert">×</button>' . Session::flash('info') . '</div></div>';
}
}
}
?>
<form action="" method="post" name="changepassword" id="changepassword" data-parsley-validate>
<fieldset>
<div class="form-group">
<label class="control-label" for="current_password">Current Password</label>
<input class="form-control" type="password" placeholder="Current Password" name="current_password" id="current_password" autofocus="" data-parsley-trigger="change" data-parsley-minlength="6" required>
</div>
<div class="form-group">
<label class="control-label" for="new_password">New Password</label>
<input class="form-control" type="password" placeholder="New Password" name="new_password" id="new_password" data-parsley-trigger="change" data-parsley-minlength="6" required>
</div>
<div class="form-group">
<label class="control-label" for="new_password_again">Confirm New Password</label>
<input class="form-control" type="password" placeholder="Repeat Password" name="new_password_again" id="new_password_again" data-parsley-trigger="change" data-parsley-equalto="#new_password" required>
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input class="btn btn-primary" style="float:left;" type="submit" value="Change Password">
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once 'footer.php'; ?>
</body>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="js/ripples.js"></script>
<script src="js/material.js"></script>
<script src="js/snackbar.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/noUiSlider/6.2.0/jquery.nouislider.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/parsley.js/2.0.5/parsley.js"></script>
<script>
$("#changepassword").parsley({
successClass: "has-success",
errorClass: "has-error",
classHandler: function (el) {
return el.$element.closest(".form-group");
},
errorsContainer: function (el) {
return el.$element.closest(".form-group");
},
errorsWrapper: "<span class='help-block'></span>",
errorTemplate: "<span></span>"
});
</script>
</html>