-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangePassword.aspx
256 lines (215 loc) · 12 KB
/
ChangePassword.aspx
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<%@ Page Title="" Language="C#" MasterPageFile="~/FDSS.master" AutoEventWireup="true" CodeFile="ChangePassword.aspx.cs" Inherits="ChangePassword" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<!-- Style.css Start -->
<link rel="stylesheet" href="files/assets/pages/chart/radial/css/radial.css" type="text/css" media="all" />
<link rel="stylesheet" type="text/css" href="css/custom.css" />
<link rel="stylesheet" type="text/css" href="files/assets/css/style.css" />
<link rel="stylesheet" type="text/css" href="files/assets/css/jquery.mCustomScrollbar.css" />
<!-- feather Awesome -->
<link rel="stylesheet" type="text/css" href="files/assets/icon/feather/css/feather.css " />
<script type="text/javascript" src="files/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="files/bower_components/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="files/bower_components/popper.js/dist/umd/popper.min.js"></script>
<script type="text/javascript" src="files/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!--Knockout Script-->
<script src="js/knockout-3.3.0.js" type="text/javascript"></script>
<script src="js/knockout.mapping-latest.js" type="text/javascript"></script>
<script src="js/knockout.validation.js" type="text/javascript"></script>
<!-- feather Awesome -->
<link rel="stylesheet" type="text/css" href="files/assets/icon/feather/css/feather.css " />
<link rel="stylesheet" type="text/css" href="files/assets/icon/ion-icon/css/ionicons.min.css" />
<link rel="stylesheet" type="text/css" href="files/assets/icon/icofont/css/icofont.css" />
<link rel="stylesheet" type="text/css" href="files/assets/icon/simple-line-icons/css/simple-line-icons.css" />
<link rel="stylesheet" type="text/css" href="files/assets/css/sweetalert.css" />
<link rel="stylesheet" type="text/css" href="files/assets/icon/material-design/css/material-design-iconic-font.min.css" />
<style>
.toggle-password {
float: right;
cursor: pointer;
margin-right: 10px;
margin-top: -30px;
font-size: 22px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<div class="row the-box transparent">
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">CHANGE PASSWORD</h3>
</div>
<div id="panel-collapse-4" class="collapse in">
<div class="panel-body form-horizontal" style="padding: 60px;">
<div class="col-sm-12">
<asp:Label ID="lblAlertPassword" runat="server" CssClass="label label-danger" EnableViewState="false" Visible="false"></asp:Label>
</div>
<div class="form-group row">
<label class="col-sm-3 control-label" style="font-size: 16px;">Password</label>
<div class="col-sm-6">
<asp:TextBox ID="txtPassword" runat="server" CssClass="form-control" ToolTip="Password" placeholder="Password" TextMode="Password" TabIndex="1" MaxLength="16" autocomplete="off"></asp:TextBox>
<i class="toggle-password fa fa-eye-slash"></i>
<p><span class="messages" id="passwordStrengthMsg" style="color: red; font-size: medium"></span></p>
</div>
<p class="help-block" id="passwordValidationMsg" style="color: red; font-size: 18px;"></p>
<div class="col-sm-3"><span class="messages" id="spanPassword" style="color: red; font-size: medium"></span></div>
</div>
<div class="form-group row">
<div class="col-sm-3 control-label" style="font-size: 16px;">Retype Password</div>
<div class="col-sm-6">
<asp:TextBox ID="txtConfirmPassword" runat="server" CssClass="form-control" ToolTip="Retype Password" placeholder="Retype Password" TextMode="Password" TabIndex="2" MaxLength="16" autocomplete="off"></asp:TextBox>
<i class="toggle-password fa fa-eye-slash"></i>
<p class="help-block">
<asp:CompareValidator ForeColor="Red" ID="cmptxtConfirmPassword" runat="server" ErrorMessage="Retype Password not same as the Password." Display="Dynamic" SetFocusOnError="true" ControlToCompare="txtPassword" ControlToValidate="txtConfirmPassword" ValidationGroup="valChangePassword" Type="String"></asp:CompareValidator>
</p>
</div>
<div class="col-sm-3"><span class="messages" id="spanRetypePassword" style="color: red; font-size: medium"></span></div>
</div>
<div class="col-sm-12" align="center">
<input type="button" class="btn btn-success f-w-100" style="width: 85px; height: auto; margin-top: -3px; background: #009933; border-radius: 2px; cursor: pointer; padding: 4px 11px;" id="btnChangePWD" value="Submit" onclick="sendRequest()" />
<input type="button" class="btn btn-success f-w-100" style="width: 85px; height: auto; margin-top: -3px; background: #009933; border-radius: 2px; cursor: pointer; padding: 4px 11px;" id="btnBack" value="Cancel" onclick="BackToList()" />
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
var passwordField = $('#<%= txtPassword.ClientID %>');
var passwordValidationMsg = $('#passwordValidationMsg');
var passwordStrengthMsg = $('#passwordStrengthMsg');
var confirmPasswordField = $('#<%= txtConfirmPassword.ClientID %>');
confirmPasswordField.prop('disabled', true);
passwordField.on('input', function () {
var password = passwordField.val().trim();
if (password.length === 0) {
passwordStrengthMsg.empty(); // Clear password strength message when password is empty
} else {
passwordValidationMsg.empty(); // Clear password required error message
validatePassword(password);
}
});
// Attach the validation function to the input field's "keyup" event
$("#<%= txtPassword.ClientID %>").on("keyup", function () {
validatePasswordOnKeyup();
});
// Attach the validation function to the input field's "keyup" event
$("#<%= txtConfirmPassword.ClientID %>").on("keyup", function () {
validateRetypePasswordOnKeyup();
});
$(".toggle-password").click(function () {
$(this).toggleClass("fa-eye fa-eye-slash");
input = $(this).parent().find("input");
if (input.attr("type") == "password") {
input.attr("type", "text");
} else {
input.attr("type", "password");
}
});
});
function validatePassword(password) {
var passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%^&*()!+=_\-])[A-Za-z\d@#$%^&*()!+=_\-]{6,}$/;
var isValid = passwordRegex.test(password);
var passwordStrengthMsg = $('#passwordStrengthMsg');
if (isValid) {
passwordStrengthMsg.text('Password strength: Strong').css('color', 'green');
} else {
passwordStrengthMsg.text('Password strength: Weak').css('color', 'red');
}
var txtPassword = $('#<%= txtPassword.ClientID %>').val();
if (txtPassword == null || txtPassword.trim() === "") {
passwordStrengthMsg.text('');
}
return isValid;
}
function validatePasswordOnKeyup() {
var password = $("#<%= txtPassword.ClientID %>").val();
var spanPassword = $("#spanPassword");
var spanRetypePassword = $("#spanRetypePassword");
var confirmPasswordField = $("#<%= txtConfirmPassword.ClientID %>");
confirmPasswordField.prop('disabled', password.trim() === "");
if (password.length === 0) {
spanPassword.text("Password is required");
spanRetypePassword.text("");
return;
}
spanPassword.text(password.length < 6 ? "Password must be at least 6 characters long" : "");
if (!/[A-Z]/.test(password)) {
spanPassword.append("<br>At least one uppercase letter");
}
if (!/[a-z]/.test(password)) {
spanPassword.append("<br>At least one lowercase letter");
}
if (!/[^A-Za-z0-9]/.test(password)) {
spanPassword.append("<br>At least one special character");
}
if (!/\d/.test(password)) {
spanPassword.append("<br>At least one digit");
}
spanRetypePassword.text("");
}
function validateRetypePasswordOnKeyup() {
var confirmPassword = $("#<%= txtConfirmPassword.ClientID %>").val();
var spanRetypePassword = $("#spanRetypePassword");
if (confirmPassword.length === 0) {
spanRetypePassword.text("Retype Password Required");
} else {
spanRetypePassword.text("");
}
}
function sendRequest() {
var isValid = true;
var txtPassword = $('#<%= txtPassword.ClientID %>').val();
var txtConfirmPassword = $('#<%= txtConfirmPassword.ClientID %>').val();
isValid = hasValue("#<%= txtPassword.ClientID %>", "#spanPassword", "Enter the Password") &&
validatePassword(txtPassword) &&
hasValue("#<%= txtConfirmPassword.ClientID %>", "#spanRetypePassword", "Enter the Retype Password") &&
(txtPassword == txtConfirmPassword);
if (isValid) {
var NewPassword = $('#<%= txtConfirmPassword.ClientID %>').val();
var dataToSend = {
newPwd: NewPassword
};
$("#btnChangePWD").attr("disabled", true);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ChangePassword.aspx/ChangeCurrentPassword",
data: JSON.stringify(dataToSend),
dataType: "json",
success: function (data) {
if (data.d >= 0) {
var inserted = data.d;
if (inserted != null) {
location.href = "Login.aspx?flagId=3";
} else {
alert('failed to update');
}
}
},
error: function (response) {
alert(response.responseText);
}
});
} else {
validatePasswordOnKeyup();
}
return isValid;
}
function hasValue(ctrlId, errDisplayCtrlId, errMsg) {
var hasIt = true;
var ctrlValue = $(ctrlId).val();
if (ctrlValue === "") {
hasIt = false;
$(errDisplayCtrlId).text(errMsg);
} else {
$(errDisplayCtrlId).text('');
}
return hasIt;
}
function BackToList() {
window.location = 'Dashboard.aspx';
}
</script>
</asp:Content>