fleet-contractor/Site/ChangePassword.aspx
2023-04-28 12:22:26 +08:00

295 lines
11 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/IronIntelMasterPage.master" AutoEventWireup="true" CodeFile="ChangePassword.aspx.cs" Inherits="ChangePassword" %>
<asp:Content ID="Content1" ContentPlaceHolderID="holder_head" runat="Server">
<style type="text/css">
body {
overflow-x: hidden;
}
.cp_body {
width: 960px;
margin: 40px 240px;
color: #666;
}
.cp_header {
line-height: 40px;
font-size: 1.8em;
}
.cp_form {
margin-top: 20px;
height: 340px;
}
.cp_button {
margin-top: 30px;
}
.cp_button input {
border: none;
background: #e7790E;
cursor: pointer;
padding: 6px;
width: 80px;
}
.cp_button input:hover {
background: #d7690E;
}
.item_header {
font-family: Arial;
font-size: 1.1em;
font-weight: bold;
line-height: 24px;
margin-top: 8px;
}
.item_label {
line-height: 18px;
}
.item_text {
line-height: 22px;
}
.item_text input {
width: 286px;
border: 1px solid #a9a9a9;
padding: 2px;
}
.item_error {
padding: 5px;
margin-top: 5px;
border: 1px solid #f00;
color: #f00;
width: 280px;
}
.item_strong {
width: 292px;
line-height: 17px;
}
#pass_progress label {
margin: 2px 4px;
}
.non {
background: none;
color: rgb(115, 124, 133);
}
.weak {
background: #f00;
color: white;
width: 33%;
}
.normal {
background: #ec6b00;
color: white;
width: 66%;
}
.strong {
background: #579705;
color: white;
width: 100%;
}
#content {
overflow-y: auto;
overflow-x: hidden;
}
</style>
<script type="text/javascript">
$(function () {
var iswrong = false;
// ChangePassword
function changepassQuery(method, param, callback, error) {
_network.request("ChangePassword.aspx?tp=ashx", -1, method, param, callback, error);
}
function CheckIfEmpty(val, errid) {
if (typeof val !== 'string' || val.length == 0) {
$(errid).text(GetTextByKey("P_CP_PLEASEENTERTHEPASSWORD", 'Please enter the password.')).show();
iswrong = true;
return false;
} else if (val[0] == ' ' || val[val.length - 1] == ' ') {
$(errid).text(GetTextByKey("P_CP_THEHEADANDTAILOFTHEPASSWORDCANNOTBESPACES", 'The head and tail of the password cannot be spaces.')).show();
iswrong = true;
return false;
} else {
$(errid).hide();
}
iswrong = false;
return true;
}
function CheckIfEmptyOrDismatch(val, v, errid) {
if (typeof val !== 'string' || val.length == 0) {
$(errid).text(GetTextByKey("P_CP_PLEASEENTERTHEPASSWORD", 'Please enter the password.')).show();
iswrong = true;
return false;
} else if (val != v) {
$(errid).text(GetTextByKey("P_CP_THEPASSWORDSYOUENTEREDDONOTMATCHCHECKYOURTYPINGANDTRYAGAIN", 'The passwords you entered do not match. Check your typing and try again.')).show();
iswrong = true;
return false;
} else {
$(errid).hide();
}
iswrong = false;
return true;
}
function CheckInfo(e) {
if (iswrong) {
// has errors;
return;
}
var oldpass = $('#txt_old_pass').val();
if (oldpass.length == 0) {
$('#old_pass_error').show();
$('#txt_old_pass').focus();
return false;
} else {
$('#old_pass_error').hide();
}
var newpass = $('#txt_new_pass').val();
if (!CheckIfEmpty(newpass, '#pass_error')) {
$('#txt_new_pass').focus();
return false;
}
var newpass2 = $('#txt_new_pass2').val();
if (!CheckIfEmptyOrDismatch(newpass2, newpass, '#pass_error2')) {
$('#txt_new_pass2').focus();
return false;
}
// strong test
if (newpass.length < 8) {
$('#pass_error').text(GetTextByKey("P_CP_PASSWORDTIPS", 'The password must be at least 8 characters.')).show();
iswrong = true;
}
if (!iswrong && getStrength(newpass) < 2) {
$('#pass_error').text(GetTextByKey("P_CP_PASSWORDTIPS1", 'The password must contain both uppercase and lowercase characters and at lease one number.')).show();
iswrong = true;
}
if (iswrong) {
$('#txt_new_pass').focus();
return false;
}
DoChangePassword(htmlencode(oldpass), htmlencode(newpass));
return true;
}
function enableUI(flag) {
$('#txt_old_pass').prop('disabled', !flag);
$('#txt_new_pass').prop('disabled', !flag);
$('#txt_new_pass2').prop('disabled', !flag);
$('#button_submit').prop('disabled', !flag);
}
function DoChangePassword(oldpass, newpass) {
enableUI(false);
changepassQuery('ChangePassword', oldpass + String.fromCharCode(170) + newpass, function (data) {
if (!data || data.length == 0) {
$('#old_pass_error').hide();
$('#txt_old_pass').val('');
$('#txt_new_pass').val('');
$('#txt_new_pass2').val('');
$('#pass_progress').attr('class', 'non').children('label').text(GetTextByKey("P_CP_PASSWORDSTRENGTH", 'Password strength'));
alert(GetTextByKey("P_CP_PASSWORDSUCCESSFULLYCHANGED", 'Password successfully changed.'));
enableUI(true);
} else {
enableUI(true);
//$('#pass_error2').text(data).show();
$('#old_pass_error').show();
$('#txt_old_pass').focus();
}
}, function (err) {
$('#pass_error2').text(GetTextByKey("P_CP_UNKNOWNERROROCCURS", 'Unknown error occurs.')).show();
enableUI(true);
});
}
function ChangeStrength() {
var pass = $(this).val();
if (typeof pass !== 'string' || pass.length == 0) {
$('#pass_progress').attr('class', 'non').children('label').text(GetTextByKey("P_CP_PASSWORDSTRENGTH", 'Password strength'));
} else if (pass.length < 6) {
$('#pass_progress').attr('class', 'weak').children('label').text(GetTextByKey("P_CP_WEAK", 'weak'));
} else {
var strength = getStrength(pass);
if (strength == 2) {
$('#pass_progress').attr('class', 'strong').children('label').text(GetTextByKey("P_CP_STRONG", 'strong'));
} else if (strength == 1) {
$('#pass_progress').attr('class', 'normal').children('label').text(GetTextByKey("P_CP_MEDIUM", 'medium'));
} else {
$('#pass_progress').attr('class', 'weak').children('label').text(GetTextByKey("P_CP_WEAK", 'weak'));
}
}
}
$('#txt_new_pass')
.bind('propertychange', ChangeStrength)
.bind('input', ChangeStrength)
.blur(function () {
var newpass = $(this).val();
CheckIfEmpty(newpass, '#pass_error');
});
$('#txt_new_pass2').blur(function () {
var newpass = $('#txt_new_pass').val();
var newpass2 = $(this).val();
CheckIfEmptyOrDismatch(newpass2, newpass, '#pass_error2');
});
$('#button_submit').click(CheckInfo);
$('#txt_old_pass').val('');
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="holder_content" runat="Server">
<div class="cp_body">
<div class="cp_header" data-lgid="P_CHANGEPASSWORD">Change Password</div>
<div class="cp_form">
<div class="item_header" data-lgid="P_CP_USERID">User ID</div>
<div class="item_label"><%=HttpUtility.HtmlEncode(UserID)%></div>
<div class="item_header" data-lgid="P_CP_OLDPASSWORD">Old Password</div>
<div class="item_text">
<input type="password" id="txt_old_pass" name="oldpass" autocomplete="off" />
</div>
<div id="old_pass_error" class="item_error" style="display: none;" data-lgid="P_CP_THEOLDPASSWORDISWRONG">The old password is wrong.</div>
<div class="item_header" data-lgid="P_CP_NEWPASSWORD">New Password</div>
<div class="item_text">
<input type="password" id="txt_new_pass" name="newpass" autocomplete="off" />
</div>
<div class="item_strong">
<div id="pass_progress" class="non">
<label data-lgid="P_CP_PASSWORDSTRENGTH">Password strength</label>
</div>
</div>
<div id="pass_error" class="item_error" style="display: none;"></div>
<div class="item_header" data-lgid="P_CP_CONFIRMNEWPASSWORD">Confirm New Password</div>
<div class="item_text">
<input type="password" id="txt_new_pass2" name="newpass2" autocomplete="off" />
</div>
<div id="pass_error2" class="item_error" style="display: none;"></div>
</div>
<div class="cp_button">
<input id="button_submit" type="button" value="OK" data-lgid="P_CP_OK" />
</div>
</div>
</asp:Content>