-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgetPassword.php
71 lines (63 loc) · 2 KB
/
forgetPassword.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
<?php
session_start(); // Detect the current session
// To Do 1: Check if user logged in
// End of To Do 1
?>
<script type="text/javascript">
function validateForm()
{
// Check if password matched
if (document.changePwd.pwd1.value != document.changePwd.pwd2.value) {
alert("Passwords not matched!");
return false; // cancel submission
}
return true; // No error found
}
</script>
<!-- Create a cenrally located container -->
<div style="width:80%; margin:auto;">
<form name="changePwd" method="post" onsubmit="return validateForm()">
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<span class="page-title">Change Password</span>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="pwd1">
New Password:</label>
<div class="col-sm-9">
<input class="form-control" name="pwd1" id="pwd1"
type="password" required />
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="pwd2">
Retype Password:</label>
<div class="col-sm-9">
<input class="form-control" name="pwd2" id="pwd2"
type="password" required />
</div>
</div>
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<button type="submit">Update</button>
</div>
</div>
</form>
<?php
// Process after user click the submit button
if (isset($_POST["pwd1"])) {
// To Do 2: Read new password entered by user
$new_pass = $_POST["pwd1"];
// To Do 3: Hash the default password
$newhashed_pwd = password_hash($new_pass, PASSWORD_DEFAULT);
// To Do 4: Update the new password hash
include_once("GeoDBConnection.php");
$qry = "UPDATE adminlogin SET Password=? WHERE LoginID=?";
$stmt = $conn ->prepare($qry);
$stmt-> bind_param("si", $newhashed, $loginId);
$stmt->execute();
$stmt->close();
}
?>
</div> <!-- Closing container -->