-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-password.php
executable file
·168 lines (149 loc) · 5.14 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
session_start();
$page_title = 'Rankings';
if (!(isset($_SESSION['login']) && $_SESSION['login'] != "")) {
header("Location: index.php");
exit();
}
include "php/header.php";
include "php/navigation.php";
?>
<script type="text/javascript">
function validateFullForm() {
// Validate the password input
var pwd1 = document.forms["registrationForm"]["password"];
var pwd2 = document.forms["registrationForm"]["password2"];
if(pwd1.value != "" && pwd1.value == pwd2.value) {
if(!checkPassword(pwd1.value)) {
alert("The password you have entered is not valid.");
pwd1.focus();
return false;
}
} else {
alert("Please check that you've entered and confirmed your password correctly.");
pwd1.focus();
return false;
}
return true;
}
function checkPassword(str) {
var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$/;
return re.test(str);
}
// Turn the password field red if not input correct (onBlur - focus leaving the field)
function validatePassword() {
var x = document.getElementById("password");
if ((x.value == null) || (x.value == "") || (!checkPassword(x.value))) {
x.style.border="1px solid red";
return false;
}
else x.style.border="1px solid green";
}
// Turn the confirm password field red if not input correct (onBlur - focus leaving the field)
function validatePassword2() {
var x = document.getElementById("password2");
var y = document.getElementById("password");
if ((x.value == null) || (x.value == "") || (!checkPassword(x.value)) || (x.value != y.value)) {
x.style.border="1px solid red";
return false;
}
else x.style.border="1px solid green";
}
function _(x){
return document.getElementById(x);
}
function ajaxObj(meth, url) {
var x = new XMLHttpRequest();
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
function changePass(){
var pwd = _("password").value;
if (pwd == ""){
_("status").innerHTML = "Please type in a new password.";
}
else {
//_("changepassbtn").style.display = "none";
_("status").innerHTML = 'Please wait ...';
//_("status").innerHTML = '<div class="spinner"></div>';
var ajax = ajaxObj("POST", "php/change-pwd.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
var response = ajax.responseText;
//alert(response);
if(response = "success"){
//alert("Gotcha!");
_("changePassForm").innerHTML = '<h3>Password successfully changed!</p>';
//$("#forgotPassForm").hide();
//$("#confirm-msg").show();
}
else if (response = "no_exist"){
_("status").innerHTML = "Sorry, that email address has not been registered.";
}
/*else if (response = "email_send_failed"){
_("status").innerHTML = "Mail function failed to execute.";
}*/
else {
_("status").innerHTML = "An unknown error occurred.";
}
}
}
ajax.send("pwd="+pwd);
}
}
function test() {
alert("<?php echo $_SESSION["username"]; ?>");
}
</script>
<!-- Main Content Section -->
<main id="main" class="main">
<div class="pagetitle d-flex justify-content-between">
<nav>
<h1>Change Password</h1>
<!-- <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="home.php">Home</a></li>
<li class="breadcrumb-item"><a href="#">Care Episodes</a></li>
<li class="breadcrumb-item active">Part #3 - 11.30</li>
</ol> -->
</nav>
</div><!-- End Page Title -->
<section class="section">
<p>Please enter a new password or return to the <a href="dashboard.php">dashboard page</a>.</p>
<form id="changePassForm" name="changePassForm" class="form-horizontal" onSubmit="return false;">
<!-- New Password -->
<div class="form-group">
<label for="password" class="col-sm-3 control-label">New Password: </label>
<div class="col-sm-5">
<input type="password" class="form-control" id="password" name="password" onBlur="return validatePassword();" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" onchange="form.password2.pattern = this.value;" />
</div>
<div class="col-sm-4"><p id="status"></p></div>
</div>
<!-- Confirm New Password -->
<div class="form-group">
<label for="password2" class="col-sm-3 control-label">Confirm New Password: </label>
<div class="col-sm-5">
<input type="password" class="form-control" id="password2" name="password2" onBlur="return validatePassword2();" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" />
</div>
<div class="col-sm-4"></div>
</div>
<div class="form-group mt-3">
<div class="col-sm-3"></div>
<div class="col-sm-5">
<input type="button" id="changepassbtn" class="btn btn-primary" value="Change password" onClick="changePass()" />
</div>
<div class="col-sm-4">
</div>
</div>
</form>
</section>
</div>
</div>
</main>
<!-- Footer -->
<?php include "php/footer.php" ?>