You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
8.6 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

$(function() {
var isOldValid = true;
//清空
$('#btn_clear').click(function () {
$("#newUserPwd").val("");
$("#newReUserPwd").val("");
isOldValid = true;
});
//提交更改
$('#btn_submit').click(function () {
if($("#newUserPwd").val() == ""){
toastr.warning("新密码不能为空!")
return false;
}
if($("#newUserPwd").val().length < 8){
toastr.warning("新密码长度小于8位")
return false;
}
if($("#newReUserPwd").val() == ""){
toastr.warning("重复密码不能为空!")
return false;
}
if($("#newReUserPwd").val().length < 8){
toastr.warning("重复密码长度小于8位")
return false;
}
//reg=/^(?=.*[a-z])(?=.*\d)[a-zA-Z\d]{8,}$/;
// reg = /^(?![\d]+$)(?![a-z]+$)(?![A-Z]+$)(?![`~!@#$%^&*()-_=+\|[{}];:'",<.>\/?]+$)[\da-zA-z`~!@#$%^&*()-_=+\|[{}];:'",<.>\/?]{8,}$/;
//~!@#$%^&*()-_=+\|[{}];:'",<.>/?
reg = /^(?![A-Za-z]+$)(?![A-Z\d]+$)(?![A-Z\W]+$)(?![a-z\d]+$)(?![a-z\W]+$)(?![\d\W]+$)\S{8,20}$/;
var mm = $("#newUserPwd").val();
if (!reg.test($("#newUserPwd").val())) {
toastr.warning("口令必须包含如下字符的组合:一个小写字母、个大写字母、一数字、一特殊字符!")
return false;
}
if($("#newReUserPwd").val() != $("#newUserPwd").val() ){
toastr.warning("重复密码与密码不一致!")
return false;
}
$.ajax({
type: "post",
url: path+"/user/updatePassword",
data:{userPwd : $("#newUserPwd").val()},
dataType:'json',
success: function(data){
if (data.code == 200){
return toastr.success("密码中不能包含账号!");
}
if(data.extend.result){
toastr.success("修改成功!");
setTimeout(function(){
window.location.reload();
},1000)
}else{
toastr.error("修改失败!");
}
}
});
});
/*//验证旧密码
$('#userPwd').blur(function () {
$.ajax({
type: "post",
url: path+"/user/updatePassword",
data:{userPwd : $("#userPwd").val()},
async:false,
success: function(data){
if( ! data.extend.result){
toastr.warning("旧密码输入错误!");
isOldValid = false;
}else{
isOldValid = true;
}
}
});
})*/
});
/**
* 密码强度动态验证
* @param passName
* @constructor
*/
function AnalyzePasswordSecurityLevel(passName) {
var password =$("#"+passName).val();
var pwdArray = new Array();
var securityLevelFlag = 0;
if (passName == "newReUserPwd") {
if(password == $("#newUserPwd").val()){
if (password.length < 8) {
if (passName == "newUserPwd"){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码长度不能小于8位");
}
if (passName == "newReUserPwd") {
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码长度不能小于8位");
}
}
else {
var securityLevelFlagArray = new Array(0, 0, 0, 0);
for (var i = 0; i < password.length; i++) {
var asciiNumber = password.substr(i, 1).charCodeAt();
if (asciiNumber >= 48 && asciiNumber <= 57) {
securityLevelFlagArray[0] = 1; //digital
}
else if (asciiNumber >= 97 && asciiNumber <= 122) {
securityLevelFlagArray[1] = 1; //lowercase
}
else if (asciiNumber >= 65 && asciiNumber <= 90) {
securityLevelFlagArray[2] = 1; //uppercase
}
else {
securityLevelFlagArray[3] = 1; //specialcase
}
}
for (var i = 0; i < securityLevelFlagArray.length; i++) {
if (securityLevelFlagArray[i] == 1) {
securityLevelFlag++;
}
}
if (passName == "newUserPwd"){
if (securityLevelFlag == 1){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全低");
}
if (securityLevelFlag == 2 || securityLevelFlag == 3){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全中等");
}
if (securityLevelFlag == 4){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全高");
}
}
if (passName == "newReUserPwd") {
if (securityLevelFlag == 1){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全低");
}
if (securityLevelFlag == 2 || securityLevelFlag == 3){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全中等");
}
if (securityLevelFlag == 4){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全高");
}
}
}
} else {
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("两次密码不相同");
}
} else {
if (password.length < 8) {
if (passName == "newUserPwd"){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码长度不能小于8位");
}
if (passName == "newReUserPwd") {
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码长度不能小于8位");
}
}
else {
var securityLevelFlagArray = new Array(0, 0, 0, 0);
for (var i = 0; i < password.length; i++) {
var asciiNumber = password.substr(i, 1).charCodeAt();
if (asciiNumber >= 48 && asciiNumber <= 57) {
securityLevelFlagArray[0] = 1; //digital
}
else if (asciiNumber >= 97 && asciiNumber <= 122) {
securityLevelFlagArray[1] = 1; //lowercase
}
else if (asciiNumber >= 65 && asciiNumber <= 90) {
securityLevelFlagArray[2] = 1; //uppercase
}
else {
securityLevelFlagArray[3] = 1; //specialcase
}
}
for (var i = 0; i < securityLevelFlagArray.length; i++) {
if (securityLevelFlagArray[i] == 1) {
securityLevelFlag++;
}
}
if (passName == "newUserPwd"){
if (securityLevelFlag == 1){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全低");
}
if (securityLevelFlag == 2 || securityLevelFlag == 3){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全中等");
}
if (securityLevelFlag == 4){
$("#newUserPwdText").text("");
$("#newUserPwdText").text("密码安全高");
}
}
if (passName == "newReUserPwd") {
if (securityLevelFlag == 1){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全低");
}
if (securityLevelFlag == 2 || securityLevelFlag == 3){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全中等");
}
if (securityLevelFlag == 4){
$("#newReUserPwdText").text("");
$("#newReUserPwdText").text("密码安全高");
}
}
}
}
}