-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_password.php
More file actions
85 lines (77 loc) · 2.19 KB
/
change_password.php
File metadata and controls
85 lines (77 loc) · 2.19 KB
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
<?php
require('resources/config.php');
if(!logged_in())header('Location: login.php');
$pagetitle = 'Change Password';
include('templates/header.php');
?>
<div class="container">
<?php
if (empty($_POST) === false) {
$required_fields = array('current_password', 'password', 'password_again');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'You need to fill in all the required fields.';
break 1;
}
}
if (md5($_POST['current_password']) === $user_data['password']) {
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 {
$errors[] = 'Your current password is incorrect.';
}
}
?>
<h1>Change Password</h1>
<?php
if (isset($_GET['success']) && empty($errors)) {
?>
<div class="success">
<strong><?php echo '<ul><li>You have been successfully changed your password!</li></ul>';?></strong>
</div>
<?php
} else {
if (empty($_POST) === false && empty($errors) === true) {
change_password($con, $session_user_id, $_POST['password']);?>
<div class="success">
<strong><?php echo output_errors($errors);?></strong>
</div>
<?php
} else if (empty($errors) === false) {
?>
<div class="error">
<strong><?php echo output_errors($errors);?></strong>
</div>
<?php
}
?>
<div class="login-form">
<form action="" method="post">
<div class="input-field">
<label for="current_password">Current password</label>
<input type="password" name="current_password" placeholder="Password">
</div>
<div class="input-field">
<label for="password">New password</label>
<input type="password" name="password" placeholder="Password">
</div>
<div class="input-field">
<label for="password_again">New password again</label>
<input type="password" name="password_again" placeholder="Password">
</div>
<div class="input-field-check">
<input class="submit-button" value="Change Password" type="submit">
</div>
</form>
<?php
}
?>
</div>
</div>
</div>
<?php include('templates/footer.php');?>
</body>
</html>