密码校验
// 密码强度校验
inputMethodPassword(value) {
console.log('value:', value)
// 密码为八位及以上并且大小写字母数字特殊字符三项都包括
var strongRegex = new RegExp('^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$', 'g')
// 密码为八位及以上并且大小写字母、数字、特殊字符三项中有两项,强度是中等
var mediumRegex = new RegExp('^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[a-z])(?=.*\\W))|((?=.*[0-9])(?=.*\\W))|((?=.*[A-Z])(?=.*\\W))).*$', 'g')
var enoughRegex = new RegExp('(?=.{8,}).*', 'g')
if (strongRegex.test(value)) {
// console.log('强密码-----',value)
this.str2 = '密码强度不错哦!'
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度至少为8位。<i>当前密码强度:强</i>'
} else if (mediumRegex.test(value)) {
// console.log('中等密码-----',value)
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度至少为8位。<i>当前密码强度:中等</i>'
this.str2 = '密码强度中等!'
} else if (enoughRegex.test(value)) {
// console.log('弱密码-----',value)
this.str2 = '密码强度太弱,请至少使用字母、数字、符号两种类型组合的密码!'
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度至少为8位。<i>当前密码强度:弱</i>'
} else {
this.note = '请至少使用大小写字母、数字、符号两种类型组合的密码,长度至少为8位。'
// console.log('密码-----',value)
}
},
// 密码中不能出现连续的数字
checkNumSeq(password) {
console.log(password, '========================')
if (password) {
var len = password.length
for (var i = 0; i < len; ++i) {
if (i + 3 < len) {
var c1 = password.charAt(i) - 0
var c2 = password.charAt(i + 1) - 0
var c3 = password.charAt(i + 2) - 0
var c4 = password.charAt(i + 3) - 0
if (isNaN(c1) || isNaN(c2) || isNaN(c3) || isNaN(c4)) { continue }
var m = c2 - c1
if (m === 1 || m === -1) {
if ((c3 - c2) === m && (c4 - c3) === m) {
return this.msgError(this.$t('密码中不能出现连续的数字'))
} else {
return this.msgError(this.$t('通过了'))
}
}
}
}
}
return false
},
// 密码中不能出现连续的字母
checkSeqChar(password){
if (password) {
var pwd = password.toUpperCase()
var len = pwd.length
for (var i = 0; i < len; ++i) {
if (i + 3 < len) {
var u1 = pwd.charCodeAt(i)
var u2 = pwd.charCodeAt(i + 1)
var u3 = pwd.charCodeAt(i + 2)
var u4 = pwd.charCodeAt(i + 3)
var m = u2 - u1
if (m === 1 || m === -1) {
if (u3 - u2 === m && u4 - u3 === m) return true
}
}
}
}
return false
}