-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwd.js
36 lines (30 loc) · 1.09 KB
/
pwd.js
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
/**
* Measure password
* @author Ahmad Al Mughrabi
* All right reserved 2015
* */
var pwd;
(function( o ) {
var rank = {'TOO_SHORT' : 0, 'WEAK' : 1, 'MEDIUM' : 2, 'STRONG' : 3, 'VERY_STRONG' : 4};
o.check = function( password, options ) {
options = options || {};
var upper = /[A-Z]/,
lower = /[a-z]/,
number = /[0-9]/,
special = /[ !"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/,
minLength = options.minLength || 8,
score = 0;
if(password.length < minLength) return rank.TOO_SHORT;
if(upper.test(password)) score ++;
if(lower.test(password)) score ++;
if(number.test(password)) score ++;
if(special.test(password)) score ++;
if(score < 3) score --;
if(password.length > minLength) { score += Math.floor((password.length-minLength) / 2); }
if(score < 3) return rank.WEAK;
if(score < 4) return rank.MEDIUM;
if(score < 6) return rank.STRONG;
return rank.VERY_STRONG;
};
o.Rank = rank;
})(pwd = pwd || {});