-
Notifications
You must be signed in to change notification settings - Fork 4
/
change-password.php
50 lines (49 loc) · 2.15 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
<?php
include_once 'core/init.php';
?>
<div id='container'>
<?php
if (empty($_POST) === false) {
if (empty($_POST['current_password']) || empty($_POST['password']) || empty($_POST['password_again'])) {
$errors[] = 'All fields are required';
} else if (Bcrypt::verifyPass($_POST['current_password'], $user['password']) === true) {
if (trim($_POST['password']) != trim($_POST['password_again'])) {
$errors[] = 'Your new passwords do not match.';
} else if (strlen($_POST['password']) < 6) {
$errors[] = 'Your password must be at least 6 characters long.';
} else if (strlen($_POST['password']) > 18) {
$errors[] = 'Your password cannot be more than 18 characters long.';
}
} else {
$errors[] = 'Your current password is incorrect.';
}
}
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
echo '<p>Your password has been changed successfully!';
echo '<br />Go back to the <a href="home.php">home page</a>';
} else { ?>
<h2>Change Password</h2>
<hr/>
<?php
if (empty($_POST) === false && empty($errors) === true) {
$users->change_password($user['id'], $_POST['password']);
header('Location: change-password.php?success');
} else if (empty($errors) === false) {
echo '<p>' . implode('</p><p>', $errors) . '</p>';
}
?>
<form action="" method='post' class='form'>
<h4>Current Password:</h4>
<input type="password" name='current_password'></input>
<h4>New Password:</h4>
<input type="password" name='password'></input>
<h4>Confirm New Password:</h4>
<input type="password" name='password_again'></input>
<br/>
<br/>
<button class="submit">Change Password</button>
</form>
<?php } ?>
</div>
<?php
?>