user-profile.js 20.3 KB
Newer Older
nabil el mahiri committed
1
!function(){"use strict";function a(a,b){this.keyboard=a,this.averageNeighbours=b,this.areAdjacent=function(a,b){if(a in this.keyboard)for(var c=0;c<this.keyboard[a].length;c++)if(null!==this.keyboard[a][c]&&this.keyboard[a][c].indexOf(b)>=0)return!0;return!1}}function b(a){this.password=a}angular.module("user-profile",[]).controller("ProfileViewCtrl",["$scope","$http","settings","$rootScope","$log","passwordScore",function(a,b,c,d,e,f){function g(){a.state="edit"}function h(){a.password={old:"","new":"",confirm:""},a.state="passwordChange",a.$watch("password.new",function(b,c){b!==c&&b&&(a.passwordScore=f(b),console.log(a.passwordScore))})}function i(){return a.status="processing",a.password["new"]!==a.password.confirm?void e.error("passwords do not match"):void b.put("/users/"+c.user._id,{password:{old:a.password.old,"new":a.password["new"]}}).success(function(){a.password=void 0,a.status="ready",a.message="password-saved",a.state="view"}).error(function(){a.status="error",a.error="password.wrong"})}d.title="Profile",angular.extend(a,{edit:g,changePassword:h,savePassword:i,view:function(){a.state="view"},status:"loading"}),e.debug("get user",c),a.user=c.user,a.status="ready",a.state="view"}]).controller("ProfileEditCtrl",["$rootScope","$http","settings","$state",function(a,b,c,d){function e(){$scope.status="saving",b.put("/users/"+c.user.id,edit).success(function(){d.go("profile")})}function f(){d.go("profile")}$scope.edit=angular.copy($scope.user),$scope.saveChanges=e,$scope.cancel=f,$scope.status="loading",b.get("/users/"+c.user.id).success(function(a){$scope.user=a,$scope.status="ready"})}]),angular.module("user-profile").factory("passwordScore",function(){return function(a){var c=new b(a),d=c.calculateEntropyScore();return d}}),b.prototype={constructor:b,LOWER:26,UPPER:26,NUMBER:10,PUNCTUATION:34,DAYS:31,MONTHS:31,YEARS:2e3,sequences:{lower:"abcdefghijklmnopqrstuvwxyz",numbers:"01234567890"},leet:{1:["i","l"],2:["n","r","z"],3:["e"],4:["a"],5:["s"],6:["g"],7:["t"],8:["b"],9:["g","o"],0:["o"],"@":["a"],"(":["c"],"[":["c"],"<":["c"],"&":["g"],"!":["i"],"|":["i","l"],"?":["n","r"],$:["s"],"+":["t"],"%":["x"]},regex:{repetition:{single:/(.)\1+/g,group:/(..+)\1+/g},date:{DMY:/(0?[1-9]|[12][0-9]|3[01])([\- \/.])?(0?[1-9]|1[012])([\- \/.])?([0-9]{2})/g,DMYY:/(0?[1-9]|[12][0-9]|3[01])([\- \/.])?(0?[1-9]|1[012])([\- \/.])?([0-9]{4})/g,MDY:/(0?[1-9]|1[012])([\- \/.])?(0?[1-9]|[12][0-9]|3[01])([\- \/.])?([0-9]{2})/g,MDYY:/(0?[1-9]|1[012])([\- \/.])?(0?[1-9]|[12][0-9]|3[01])([\- \/.])?([0-9]{4})/g,YDM:/([0-9]{2})([\- \/.])?(0?[1-9]|[12][0-9]|3[01])([\- \/.])?(0?[1-9]|1[012])/g,YYDM:/([0-9]{4})([\- \/.])?(0?[1-9]|[12][0-9]|3[01])([\- \/.])?(0?[1-9]|1[012])/g,YMD:/([0-9]{2})([\- \/.])?(0?[1-9]|1[012])([\- \/.])?(([0-9]{2})?[0-9]{2})(0?[1-9]|[12][0-9]|3[01])/g,YYMD:/([0-9]{4})([\- \/.])?(0?[1-9]|1[012])([\- \/.])?(([0-9]{2})?[0-9]{2})(0?[1-9]|[12][0-9]|3[01])/g,DM:/(0?[1-9]|[12][0-9]|3[01])([\- \/.])?(0?[1-9]|1[012])/g,MY:/(0?[1-9]|1[012])([\- \/.])?([0-9]{2})/g,MYY:/(0?[1-9]|1[012])([\- \/.])?([0-9]{4})/g},number:/[0-9]+/,numberOnly:/^[0-9]+$/,punctuation:/[\^°!"§\$%&\/\(\)=\?\\\.:,;\-_#'\+~\*<>\|\[\]\{\}]+/,punctuationOnly:/^[\^°!"§\$%&\/\(\)=\?\\\.:,;\-_#'\+~\*<>\|\[\]\{\}]+$/,lower:/[a-z]+/,lowerOnly:/^[a-z]+$/,upper:/[A-Z]+/,upperOnly:/^[A-Z]+$/,upperFirst:/^[A-Z]+[A-Za_z]*$/,upperFirstOnly:/^[A-Z]{1}[a-z]+$/},keyboards:{QWERTZ:new a({"^":[null,null,null,"^°","1!",null,null],"°":[null,null,null,"^°","1!",null,null],1:[null,null,"^°","1!",'2"',null,"qQ@"],"!":[null,null,"^°","1!",'2"',null,"qQ@"],2:[null,null,"1!",'2"',"3§","qQ@","wW"],'"':[null,null,"1!",'2"',"3§","qQ@","wW"],3:[null,null,'2"',"3§","4$","wW","eE€"],"§":[null,null,'2"',"3§","4$","wW","eE€"],4:[null,null,"3§","4$","5%","eE€","rR"],$:[null,null,"3§","4$","5%","eE€","rR"],5:[null,null,"4$","5%","6&","rR","tT"],"%":[null,null,"4$","5%","6&","rR","tT"],6:[null,null,"5%","6&","7/{","tT","yY"],"&":[null,null,"5%","6&","7/{","tT","yY"],7:[null,null,"6&","7/{","8([","yY","uU"],"/":[null,null,"6&","7/{","8([","yY","uU"],"{":[null,null,"6&","7/{","8([","yY","uU"],8:[null,null,"7/{","8([","9)]","uU","iI"],"(":[null,null,"7/{","8([","9)]","uU","iI"],"[":[null,null,"7/{","8([","9)]","uU","iI"],9:[null,null,"8([","9)]","0=}","iI","oO"],")":[null,null,"8([","9)]","0=}","iI","oO"],"]":[null,null,"8([","9)]","0=}","iI","oO"],0:[null,null,"9)]","0=}","ß?\\","oO","pP"],"=":[null,null,"9)]","0=}","ß?\\","oO","pP"],"}":[null,null,"9)]","0=}","ß?\\","oO","pP"],"ß":[null,null,"0=}","ß?\\","´`","pP","üÜ"],"?":[null,null,"0=}","ß?\\","´`","pP","üÜ"],"\\":[null,null,"0=}","ß?\\","´`","pP","üÜ"],"`":[null,null,"ß?\\","´`",null,"üÜ","+*~"],"´":[null,null,"ß?\\","´`",null,"üÜ","+*~"],q:["1!",'2"',null,"qQ@","wW",null,"aA"],Q:["1!",'2"',null,"qQ@","wW",null,"aA"],"@":["1!",'2"',null,"qQ@","wW",null,"aA"],w:['2"',"3§","qQ@","wW","eE","aA","sS"],W:['2"',"3§","qQ@","wW","eE€","aA","sS"],e:["3§","4$","wW","eE€","rR","sS","dD"],E:["3§","4$","wW","eE€","rR","sS","dD"],"€":["3§","4$","wW","eE€","rR","sS","dD"],r:["4$","5%","eE€","rR","tT","dD","fF"],R:["4$","5%","eE€","rR","tT","dD","fF"],t:["5%","6&","rR","tT","zZ","fF","gG"],T:["5%","6&","rR","tT","zZ","fF","gG"],z:["6&","7/{","tT","zZ","uU","gG","hH"],Z:["6&","7/{","tT","zZ","uU","gG","hH"],u:["7/{","8([","zZ","uU","iI","hH","jJ"],U:["7/{","8([","zZ","uU","iI","hH","jJ"],i:["8([","9)]","uU","iI","oO","jJ","kK"],I:["8([","9)]","uU","iI","oO","jJ","kK"],o:["9)]","0=}","iI","oO","pP","kK","lL"],O:["9)]","0=}","iI","oO","pP","kK","lL"],p:["0=}","ß?\\","oO","pP","üÜ","lL","öÖ"],P:["0=}","ß?\\","oO","pP","üÜ","lL","öÖ"],"ü":["ß?\\","´`","pP","üÜ","+*~","öÖ","äÄ"],"Ü":["ß?\\","´`","pP","üÜ","+*~","öÖ","äÄ"],"+":["´``",null,"üÜ","+*~",null,"äÄ","'#"],"*":["´``",null,"üÜ","+*~",null,"äÄ","'#"],"~":["´``",null,"üÜ","+*~",null,"äÄ","'#"],a:["qQ@","wW",null,"aA","sS","<>|","yY"],A:["qQ@","wW",null,"aA","sS","<>|","yY"],s:["wW","eE","aA","sS","dD","yY","xX"],S:["wW","eE","aA","sS","dD","yY","xX"],d:["eE","rR","sS","dD","fF","xX","cC"],D:["eE","rR","sS","dD","fF","xX","cC"],f:["rR","tT","dD","fF","gG","cC","vV"],F:["rR","tT","dD","fF","gG","cC","vV"],g:["tT","zZ","fF","gG","hH","vV","bB"],G:["tT","zZ","fF","gG","hH","vV","bB"],h:["zZ","uU","gG","hH","jJ","bB","nN"],H:["zZ","uU","gG","hH","jJ","bB","nN"],j:["uU","iI","hH","jJ","kK","nN","mM"],J:["uU","iI","hH","jJ","kK","nN","mM"],k:["iI","oO","jJ","kK","lL","mM",",;"],K:["iI","oO","jJ","kK","lL","mM",",;"],l:["oO","pP","kK","lL","öÖ",",;",".:"],L:["oO","pP","kK","lL","öÖ",",;",".:"],"ö":["pP","üÜ","lL","öÖ","äÄ",".:","-_"],"Ö":["pP","üÜ","lL","öÖ","äÄ",".:","-_"],"ä":["üÜ","+*~","öÖ","äÄ","#'","-_",null],"Ä":["üÜ","+*~","öÖ","äÄ","#'","-_",null],"#":["+*~",null,"äÄ","#'",null,null,null],"'":["+*~",null,"äÄ","#'",null,null,null],"<":[null,"aA",null,"<>|","yY",null,null],">":[null,"aA",null,"<>|","yY",null,null],"|":[null,"aA",null,"<>|","yY",null,null],y:["aA","sS","<>|","yY","xX",null,null],Y:["aA","sS","<>|","yY","xX",null,null],x:["sS","dD","yY","xX","cC",null,null],X:["sS","dD","yY","xX","cC",null,null],c:["dD","fF","xX","cC","vV",null,null],C:["dD","fF","xX","cC","vV",null,null],v:["fF","gG","cC","vV","bB",null,null],V:["fF","gG","cC","vV","bB",null,null],b:["gG","hH","vV","bB","nN",null,null],B:["gG","hH","vV","bB","nN",null,null],n:["hH","jJ","bB","nN","mM",null,null],N:["hH","jJ","bB","nN","mM",null,null],m:["jJ","kK","nN","mM",",;",null,null],M:["jJ","kK","nN","mM",",;",null,null],",":["kK","lL","mM",",;",".:",null,null],";":["kK","lL","mM",",;",".:",null,null],".":["lL","öÖ",",;",".:","-_",null,null],":":["lL","öÖ",",;",".:","-_",null,null],"-":["öÖ","ä",".:","-_",null,null,null],_:["öÖ","ä",".:","-_",null,null,null]},4.571428571),QWERTY:new a({"~":[null,null,null,"~`","1!",null,null],"`":[null,null,null,"~`","1!",null,null],1:[null,null,"`~","1!","2@",null,"qQ"],"!":[null,null,"`~","1!","2@",null,"qQ"],2:[null,null,"1!","2@","3#","qQ","wW"],"@":[null,null,"1!","2@","3#","qQ","wW"],3:[null,null,"2@","3#","4$","wW","eE"],"#":[null,null,"2@","3#","4$","wW","eE"],4:[null,null,"3#","4$","5%","eE","rR"],$:[null,null,"3#","4$","5%","eE","rR"],5:[null,null,"4$","5%","6^","rR","tT"],"%":[null,null,"4$","5%","6^","rR","tT"],6:[null,null,"5%","6^","7&","tT","yY"],"^":[null,null,"5%","6^","7&","tT","yY"],7:[null,null,"6^","7&","8*","yY","uU"],"&":[null,null,"6^","7&","8*","yY","uU"],8:[null,null,"7&","8*","9(","uU","iI"],"*":[null,null,"7&","8*","9(","uU","iI"],9:[null,null,"8*","9(","0)","iI","oO"],"(":[null,null,"8*","9(","0)","iI","oO"],0:[null,null,"9(","0)","-_","oO","pP"],")":[null,null,"9(","0)","-_","oO","pP"],"-":[null,null,"0)","-_","=+","pP","[{"],_:[null,null,"0)","-_","=+","pP","[{"],"=":[null,null,"-_","=+","\\|","{[","}]"],"+":[null,null,"-_","=+","\\|","{[","}]"],"\\":[null,null,"=+","\\|",null,"}]",null],"|":[null,null,"=+","\\|",null,"}]",null],q:["1!","2@",null,"qQ","wW",null,"aA"],Q:["1!","2@",null,"qQ","wW",null,"aA"],w:["2@","3#","qQ","wW","eE","aA","sS"],W:["2@","3#","qQ","wW","eE","aA","sS"],e:["3#","4$","wW","eE","rR","sS","dD"],E:["3#","4$","wW","eE","rR","sS","dD"],r:["4$","5%","eE","rR","tT","dD","fF"],R:["4$","5%","eE","rR","tT","dD","fF"],t:["5%","6^","rR","tT","yY","fF","gG"],T:["5%","6^","rR","tT","yY","fF","gG"],y:["6^","7&","tT","yY","uU","gG","hH"],Y:["6^","7&","tT","yY","uU","gG","hH"],u:["7&","8*","yY","uU","iI","hH","jJ"],U:["7&","8*","yY","uU","iI","hH","jJ"],i:["8*","9(","uU","iI","oO","jJ","kK"],I:["8*","9(","uU","iI","oO","jJ","kK"],o:["9(","0)","iI","oO","pP","kK","lL"],O:["9(","0)","iI","oO","pP","kK","lL"],p:["0)","-_","oO","pP","[{","lL",":;"],P:["0)","-_","oO","pP","[{","lL",":;"],"[":["-_","=+","pP","[{","]}",":;","'\""],"{":["-_","=+","pP","[{","]}",":;","'\""],"]":["=+","\\|","[{","]}",null,"'\"",null],"}":["=+","\\|","[{","]}",null,"'\"",null],a:["qQ","wW",null,"aA","sS",null,"zZ"],A:["qQ","wW",null,"aA","sS",null,"zZ"],s:["wW","eE","aA","sS","dD","zZ","xX"],S:["wW","eE","aA","sS","dD","zZ","xX"],d:["eE","rR","sS","dD","fF","xX","cC"],D:["eE","rR","sS","dD","fF","xX","cC"],f:["rR","tT","dD","fF","gG","cC","vV"],F:["rR","tT","dD","fF","gG","cC","vV"],g:["tT","yY","fF","gG","hH","vV","bB"],G:["tT","yY","fF","gG","hH","vV","bB"],h:["yY","uU","gG","hH","jJ","bB","nN"],H:["yY","uU","gG","hH","jJ","bB","nN"],j:["uU","iI","hH","jJ","kK","nN","mM"],J:["uU","iI","hH","jJ","kK","nN","mM"],k:["iI","oO","jJ","kK","lL","mM",",;"],K:["iI","oO","jJ","kK","lL","mM",",;"],l:["oO","pP","kK","lL",":;",",<",".>"],L:["oO","pP","kK","lL",":;",",<",".>"],":":["pP","[{","lL",":;","'\"",".>","?/"],";":["pP","[{","lL",":;","'\"",".>","?/"],"'":["[{","]}",":;","'\"",null,"?/",null],'"':["[{","]}",":;","'\"",null,"?/",null],z:["aA","sS",null,"zZ","xX",null,null],Z:["aA","sS",null,"zZ","xX",null,null],x:["sS","dD","zZ","xX","cC",null,null],X:["sS","dD","zZ","xX","cC",null,null],c:["dD","fF","xX","cC","vV",null,null],C:["dD","fF","xX","cC","vV",null,null],v:["fF","gG","cC","vV","bB",null,null],V:["fF","gG","cC","vV","bB",null,null],b:["gG","hH","vV","bB","nN",null,null],B:["gG","hH","vV","bB","nN",null,null],n:["hH","jJ","bB","nN","mM",null,null],N:["hH","jJ","bB","nN","mM",null,null],m:["jJ","kK","nN","mM",",<",null,null],M:["jJ","kK","nN","mM",",<",null,null],",":["kK","lL","mM",",<",".>",null,null],"<":["kK","lL","mM",",<",".>",null,null],".":["lL",":;",",<",".>","/?",null,null],">":["lL",":;",",<",".>","/?",null,null],"/":[":;","'\"",".>","/?",null,null,null],"?":[":;","'\"",".>","/?",null,null,null]},4.571428571),QWERTZNumpad:new a({0:["1","2",",",null],",":["3","0",null,null],1:["4",null,"2","0"],2:["5","1","3","0"],3:["3","2",null,","],4:["7",null,"5","1"],5:["8","4","6","2"],6:["9","5","6","2"],7:[null,null,"8","4"],8:["/","7","9","5"],9:["*","8","+","6"],"+":["-","9","6",null],"/":[null,null,"*","8"],"*":[null,"/","-","9"],"-":[null,"*",null,"+"]},3),QWERTYNumpad:new a({0:["1","2",",",null],",":["3","0",null,null],1:["4",null,"2","0"],2:["5","1","3","0"],3:["6","2",null,","],4:["7",null,"5","1"],5:["8","4","6","2"],6:["9","5","+","2"],7:[null,null,"8","4"],8:["/","7","9","5"],9:["*","8","+","6"],"+":["-","9","6",null],"/":[null,null,"*","8"],"*":[null,"/","-","9"],"-":[null,"*",null,"+"]},3)},cache:{clear:function(){for(var a in this)"set"!==a&&"clear"!==a&&(this[a]=void 0)},set:function(a,b){this[a]=b}},lg:function(a){return Math.log(a)/Math.log(2)},calculateAverageTimeToCrack:function(a,b){return.5*Math.pow(2,a)*.005/b},calculateBruteForceEntropy:function(){var a=0;this.regex.lower.test(this.password)&&(a+=this.LOWER),this.regex.upper.test(this.password)&&(a+=this.UPPER),this.regex.number.test(this.password)&&(a+=this.NUMBER),this.regex.punctuation.test(this.password)&&(a+=this.PUNCTUATION);var b=this.lg(a)*this.password.length;return this.cache.set("naiveEntropy",b),b},collectMatches:function(a,b){a=void 0===a?[]:a,b=void 0===b||b,b===!0&&void 0!==this.options&&(a=a.concat(this.options));for(var c=[],d=0;d<a.length;d++){var e=[];if(!(!1 in a[d])){switch(a[d].type){case"dictionary":if("dictionary"in a[d]&&(e=this.collectDictionaryMatches(a[d].dictionary),"leet"in a[d]&&a[d].leet===!0)){var f=this.collectLeetSpeakMatches(a[d].dictionary);e=e.concat(f)}break;case"keyboard":"keyboard"in a[d]&&(e=this.collectKeyboardMatches(a[d].keyboard));break;case"repetition":e=this.collectRepetitionMatches();break;case"sequences":e=this.collectSequenceMatches();break;case"dates":e=this.collectDateMatches()}"key"in a[d]&&this.cache.set(a[d].key,e),c=c.concat(e)}}return c},calculateEntropyScore:function(a,b){for(var c=this.collectMatches(a,b),d=[],e=[],f=this.calculateBruteForceEntropy(this.password),g=0;g<this.password.length;g++){c[c.length]={pattern:this.password[g],entropy:this.calculateBruteForceEntropy(this.password[g]),start:g,end:g,type:"letter"},d[g]=Number.POSITIVE_INFINITY;for(var h=0;h<c.length;h++){var i=c[h].start,j=c[h].end;if(j===g){var f=c[h].entropy;i>0&&(f+=d[i-1]),f<d[g]&&(d[g]=f,e[g]=c[h])}}}for(var k=[],g=this.password.length-1;g>=0;)e[g]?(k[k.length]=e[g],g=e[g].start-1):g--;return this.cache.set("minimumMatches",k),this.cache.set("entropy",d[this.password.length-1]),d[this.password.length-1]},collectDictionaryMatches:function(a){for(var b=[],c=0;c<this.password.length;c++)for(var d=c;d<this.password.length;d++){var e=this.password.substring(c,d+1),f=e.toLowerCase(),g=this.getReversedString(f);f in a&&a[f]&&(b[b.length]={pattern:e,entropy:this.calculateDictionaryEntropy(e,f,a[f]),start:c,end:d,type:"dictionary"}),g in a&&a[g]&&(b[b.length]={pattern:e,entropy:this.calculateReversedDictionaryEntropy(e,f,a[f]),start:c,end:d,type:"dictionary"})}return b},calculateDictionaryEntropy:function(a,b,c){return this.regex.lower.test(a)&&this.regex.upper.test(a)?this.regex.upperFirstOnly.test(a)?this.lg(c)+1:this.lg(c)+a.length:this.lg(c)},calculateReversedDictionaryEntropy:function(a,b,c){return this.calculateDictionaryEntropy(a,b,c)+1},collectLeetSpeakMatches:function(a){for(var b=[],c=this.collectLeetSpeakSubstitutions(this.password),d=0;d<c.length;d++)for(var e=0;e<c[d].length;e++)for(var f=e;f<c[d].length;f++){var g=c[d].substring(e,f+1),h=g.toLowerCase(),i=this.getReversedString(h),j=this.password.substring(e,f+1);h in a&&a[h]&&(b[b.length]={pattern:j,entropy:this.calculateLeetSpeakEntropy(this.password.substring(e,f+1),h,a[h]),start:e,end:f,type:"leet"}),i in a&&a[h]&&(b[b.length]={pattern:j,entropy:this.calculateReversedLeetSpeakEntropy(this.password.substring(e,f+1),h,a[h]),start:e,end:f,type:"leet"})}return b},calculateLeetSpeakEntropy:function(a,b,c){var d=1;for(var e in this.leet)a.indexOf(e)>=0&&(d*=this.leet[e].length+1);return this.calculateDictionaryEntropy(a,b,c)+this.lg(d)},calculateReversedLeetSpeakEntropy:function(a,b,c){return this.calculateLeetSpeakEntropy(a,b,c)+1},collectLeetSpeakSubstitutions:function(){var a={};for(var b in this.leet)this.password.indexOf(b)>=0&&(a[b]=this.leet[b]);var c=function(b){if(b[0]in a){if(1===b.length)return a[b[0]];for(var d=c(b.substring(1,b.length)),e=[],f=0;f<d.length;f++)for(var g=0;g<a[b[0]].length;g++)e[e.length]=a[b[0]][g]+d[f];return e}if(1===b.length)return[b[0]];for(var d=c(b.substring(1,b.length)),e=[],f=0;f<d.length;f++)e[e.length]=b[0]+d[f];return e};return c(this.password)},collectKeyboardMatches:function(a){for(var b=[],c=this.password[0],d=0,e=0,f=0;f<this.password.length-1;f++)a.areAdjacent(this.password[f],this.password[f+1])?(c+=this.password[f+1],this.password[f+1]!==this.password[f]&&d++):(b[b.length]={pattern:c,entropy:this.calculateKeyboardEntropy(c,d,a),start:e,end:f,type:"keyboard"},c=this.password[f+1],d=0,e=f+1);return c.length>0&&(b[b.length]={pattern:c,entropy:this.calculateKeyboardEntropy(c,d,a),start:e,end:this.password.length-1,type:"keyboard"}),b},calculateKeyboardEntropy:function(a,b,c){var d=1;return this.regex.lower.test(a[0])?d=this.LOWER:this.regex.upper.test(a[0])?d=this.UPPER:this.regex.number.test(a[0])?d=this.NUMBER:this.regex.punctuation.test(a[0])&&(d=this.PUNCTUATION),this.lg(d)+b*this.lg(c.averageNeighbours)},collectRepetitionMatches:function(){for(var a=[],b=this.password.match(this.regex.repetition.single)||[],c=0;c<b.length;c++)a[a.length]={pattern:b[c],entropy:this.calculateSingleRepetitionEntropy(b[c]),start:this.password.indexOf(b[c]),end:this.password.indexOf(b[c])+b[c].length-1,type:"repetition"};for(var d=this.password.match(this.regex.repetition.group)||[],c=0;c<d.length;c++)a[a.length]={pattern:d[c],entropy:this.calculateGroupRepetitionEntropy(d[c]),start:this.password.indexOf(d[c]),end:this.password.indexOf(d[c])+d[c].length-1,type:"repetition"};return a},calculateSingleRepetitionEntropy:function(a){return this.regex.number.test(a)?this.lg(this.NUMBER*a.length):this.regex.lower.test(a)||this.regex.upper.test(a)?this.lg(this.LOWER*a.length):this.regex.punctuation.test(a)?this.lg(this.PUNCTUATION*a.length):this.calculateBruteForceEntropy(a)},calculateGroupRepetitionEntropy:function(a){for(var b=this.regex.repetition.group.exec(a),c=a.length;null!==b;)c=b[1].length,b=this.regex.repetition.group.exec(b[1]);var d=0;return this.regex.number.test(a)&&(d+=this.NUMBER),(this.regex.lower.test(a)||this.regex.upper.test(a))&&(d+=this.LOWER),this.regex.punctuation.test(a)&&(d+=this.PUNCTUATION),this.lg(d*c)},collectSequenceMatches:function(){for(var a="",b="",c="",d="",e=0;e<this.password.length;e++)for(var f=e+2;f<=this.password.length;f++){var g=this.password.substring(e,f),h=g.toLowerCase(),i=this.getReversedString(h);0!==h.length&&(this.sequences.lower.indexOf(h)>=0&&h.length>a.length&&(a=g),this.sequences.lower.indexOf(i)>=0&&h.length>b.length&&(b=g),this.sequences.numbers.indexOf(h)>=0&&h.length>c.length&&(c=g),this.sequences.numbers.indexOf(i)>=0&&h.length>c.length&&(d=g))}var j=[];return a.length>0&&(j[j.length]={pattern:a,entropy:this.calculateSequenceEntropy(a),start:this.password.indexOf(a),end:this.password.indexOf(a)+a.length-1,type:"sequence"}),b.length>0&&(j[j.length]={pattern:b,entropy:this.calculateSequenceEntropy(b),start:this.password.indexOf(b),end:this.password.indexOf(b)+b.length-1,type:"sequence"}),c.length>0&&(j[j.length]={pattern:c,entropy:this.calculateSequenceEntropy(c),start:this.password.indexOf(c),end:this.password.indexOf(c)+c.length-1,type:"sequence"}),d.length>0&&(j[j.length]={pattern:d,entropy:this.calculateSequenceEntropy(d),start:this.password.indexOf(d),end:this.password.indexOf(d)+d.length-1,type:"sequence"}),j},calculateSequenceEntropy:function(a){return this.regex.number.test(a)?this.lg(a.length*this.NUMBER):this.regex.lowerOnly.test(a)?this.lg(a.length*this.LOWER):this.regex.upperOnly.test(a)?this.lg(a.length*this.LOWER):this.regex.upper.test(a)&&this.regex.upper.test(a)?this.lg(a.length*(this.LOWER+this.UPPER)):this.calculateBruteForceEntropy(a)},calculateReversedSequenceEntropy:function(a){return this.calculateSequenceEntropy(a)+1},collectDateMatches:function(){var a=[];for(var b in this.regex.date)for(var c=this.password.match(this.regex.date[b])||[],d=0;d<c.length;d++)if(c[d].length>0){var e=this.password.indexOf(c[d]);a[a.length]={pattern:c[d],entropy:this.calculateDateEntropy(c[d],b),start:e,end:e+c[d].length-1,type:"date"}}return a},calculateDateEntropy:function(a,b){switch(b){case"DMY":case"MDY":case"YDM":case"YMD":return this.lg(this.DAYS*this.MONTHS*10*10);case"DMYY":case"MDYY":case"YYDM":case"YYMD":return this.lg(this.DAYS*this.MONTHS*this.YEARS);case"DM":return this.lg(this.DAYS*this.MONTHS);case"MY":return this.lg(10*this.MONTHS*10);case"MYY":return this.lg(this.MONTHS*this.YEARS)}return this.calculateBruteForceEntropy(a)},getReversedString:function(a){return a.split("").reverse().join("")}}}();