-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-password.php
56 lines (39 loc) · 1.49 KB
/
change-password.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
<?php
include("/Users/Donovan/Sites/sn/classes/DB.php");
include("/Users/Donovan/Sites/sn/classes/Login.php");
if( Login::isLoggedIn() ){
if(isset($_POST['changepassword'])){
$oldpassword = $_POST['oldpassword'];
$newpassword = $_POST['newpassword'];
$newpasswordrepeat = $_POST['newpasswordrepeat'];
$userid = Login::isLoggedIn();
if(password_verify($oldpassword, DB::query('SELECT password FROM users WHERE id = :userid', array(':userid' => $userid))[0]['password'])){
if($newpassword == $newpasswordrepeat){
if (strlen($newpassword) >= 6 && strlen($newpassword) <= 60) {
DB::query('UPDATE users SET password=:newpassword WHERE id=:userid', array(':newpassword'=>password_hash($newpassword, PASSWORD_BCRYPT), ':userid'=> $userid));
echo 'Password changed successfully.';
}
else{
echo "Password is too short";
}
}
else{
echo "Passwords don't match!";
}
}
else{
echo 'Incorrect old password!';
}
}
}
else{
die('Not logged in');
}
?>
<h1>Change your Password</h1>
<form action="change-password.php" method="post">
<input type = "password" name="oldpassword" value="" placeholder="Current Password...">
<input type = "password" name="newpassword" value="" placeholder = "New Password...">
<input type = "password" name = "newpasswordrepeat" value="" placeholder="Reapeat Password...">
<input type="submit" name="changepassword" value="Change Password">
</form>