forked from chilian/password-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_evaluator.min.js
11 lines (9 loc) · 5.1 KB
/
password_evaluator.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
password-evaluator v 0.2
http://cc-web.eu/projects/javascript/password-evaluator
Copyright 2012, Christoph Chilian <dev@cc-web.eu>
Licensed under the MIT.
http://cc-web.eu/projects/javascript/password-evaluator/license
Date: 2012-01-14 14:51:24 +0100
*/
((function(){this.PasswordEvaluator=function(){function a(a){this.debug_mode=a!=null?a:!1,this.score=0}return a.prototype.logger=function(a,b){b==null&&(b=2);if(this.debug_mode===!0&&typeof console!="undefined")switch(parseInt(b)){case 1:console.log(a);break;case 2:console.debug(a);break;case 3:console.info(a);break;case 4:console.warn(a);break;case 5:console.error(a)}else this.debug_mode===!0&&alert(a);return a},a.prototype.check_password=function(a){return a==null&&(a=""),this.score=0,a===""&&this.logger("Attention: no password is given!!!",3),this.logger("start checking pw",1),this.score+=this.calc_score_number_of_characters(a),this.score+=this.calc_score_lowercase_letters(a),this.score+=this.calc_score_uppercase_letters(a),this.score+=this.calc_score_numbers(a),this.score+=this.calc_score_symbols(a),this.score+=this.calc_score_middle_numbers_or_symbols(a),this.score-=this.calc_score_letters_only(a),this.score-=this.calc_score_numbers_only(a),this.score-=this.calc_score_repeat_characters(a),this.score-=this.calc_score_consecutive_lc_letters_and_uc_letters_and_numbers(a),this.score-=this.calc_score_seq_alpha_or_numeric_or_symbols(a),this.logger("finished! The final score: "+this.score,1),this.score=this.score>100?100:this.score<0?0:this.score},a.prototype.calc_score_number_of_characters=function(a){var b;return b=parseInt(a.length*4),this.logger("Score=> number of characters: "+b),b},a.prototype.calc_score_lowercase_letters=function(a){var b,c;return b=this.count_regex_matches(a,/[a-z]/g),c=b<a.length&&b>=1?parseInt((a.length-b)*2):0,this.logger("Score=> lowercase_letters: "+c),c},a.prototype.calc_score_uppercase_letters=function(a){var b,c;return b=this.count_regex_matches(a,/[A-Z]/g),c=b<a.length&&b>=1?parseInt((a.length-b)*2):0,this.logger("Score=> uppercase_letters: "+c),c},a.prototype.calc_score_numbers=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[0-9]/g)*4),this.logger("Score=> numbers: "+b),b},a.prototype.calc_score_symbols=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[^a-zA-Z0-9_]/g)*6),this.logger("Score=> symbols: "+b),b},a.prototype.calc_score_middle_numbers_or_symbols=function(a){var b;return b=parseInt(this.count_regex_matches(a.substring(1,a.length-1),/([\W]|[\d])/ig)*2),this.logger("Score=> middle_numbers_or_symbols: "+b),b},a.prototype.calc_score_letters_only=function(a){var b;return b=this.count_regex_matches(a,/[^a-z]/ig)?0:parseInt(this.count_regex_matches(a,/[a-z]/ig)),this.logger("Score=> letters_only: -"+b),b},a.prototype.calc_score_numbers_only=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[^0-9]/))>0?0:a.length,this.logger("Score=> numbers_only: -"+b),b},a.prototype.calc_score_repeat_characters=function(a){var b,c,d,e,f,g,h,i,j,k,l,m;f=0,g=0,e=!1,c=a.replace(/\s+/g,"").split(/\s*/);for(j=0,l=c.length;j<l;j++){b=c[j],e=!1;for(k=0,m=c.length;k<m;k++)d=c[k],b===d&&j!==k&&(e=!0,g+=Math.abs(c.length/(k-j)));e&&(f++,h=c.length-f,h?g=Math.ceil(g/h):g=Math.ceil(g))}return i=g,this.logger("Score=> repeat_characters: -"+i),i},a.prototype.calc_score_consecutive_lowercase_letters=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[a-z]/g))*2,this.logger("Score=> consecutive_lowercase_letters: -"+b),b},a.prototype.calc_score_consecutive_uppercase_letters=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[A-Z]/g))*2,this.logger("Score=> consecutive_uppercase_letters: -"+b),b},a.prototype.calc_score_consecutive_numbers=function(a){var b;return b=parseInt(this.count_regex_matches(a,/[0-9]/g))*2,this.logger("Score=> consecutive_numbers: -"+b),b},a.prototype.calc_score_consecutive_lc_letters_and_uc_letters_and_numbers=function(a){var b,c,d,e,f,g,h,i,j,k,l;h="",j="",i="",d=0,f=0,e=0,b=a.replace(/\s+/g,"").split(/\s*/);for(k=0,l=b.length;k<l;k++)c=b[k],c.match(/[a-z]/)&&(h!==""&&h+1===k&&d++,h=k),c.match(/[A-Z]/)&&(j!==""&&j+1===k&&f++,j=k),c.match(/[0-9]/)&&(i!==""&&i+1===k&&e++,i=k);return this.logger("Score=> consecutive_lowercase: -"+d*2,1),this.logger("Score=> consecutive_uppercase: -"+f*2,1),this.logger("Score=> consecutive_number: -"+e*2,1),g=(d+f+e)*2},a.prototype.calc_score_seq_alpha_or_numeric_or_symbols=function(a){var b,c,d,e,f,g,h,i;f="abcdefghijklmnopqrstuvwxyz",h="012345678910",i='°!"§$%&/()=?`',b=0,c=0,d=0,a=a.toLowerCase();for(g=0;g<=23;g++)this.check_seq_fwd_and_rev(a,f,g)&&(b++,this.check_seq_fwd_and_rev(a,h,g)&&(c++,this.check_seq_fwd_and_rev(a,i,g)&&d++));return this.logger("Score=> seq_alpha: -"+b*3,1),this.logger("Score=> seq_numeric: -"+c*3,1),this.logger("Score=> seq_symbols: -"+d*3,1),e=(b+c+d)*3},a.prototype.count_regex_matches=function(a,b){var c;return a==null&&(a=""),b==null&&(b=/[0-9]/g),c=a.match(b),c?c.length:0},a.prototype.check_seq_fwd_and_rev=function(a,b,c,d){var e,f,g,h,i;d==null&&(d=3),f=b.substring(c,parseInt(c+d)),g="";for(h=0,i=a.length;h<i;h++)e=a[h],g=a.charAt(h)+g;return a.indexOf(f)!==-1||a.indexOf(g)!==-1},a}()})).call(this)