var shortPass="สั้นเกินไป";var badPass="ปานกลาง";var goodPass="ดี";var strongPass="ดีมาก";function passwordStrength(A,B){score=0;if(A.length<6){return shortPass}if(A.toLowerCase()==B.toLowerCase()){return badPass}score+=A.length*4;score+=(checkRepetition(1,A).length-A.length)*1;score+=(checkRepetition(2,A).length-A.length)*1;score+=(checkRepetition(3,A).length-A.length)*1;score+=(checkRepetition(4,A).length-A.length)*1;if(A.match(/(.*[0-9].*[0-9].*[0-9])/)){score+=5}if(A.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){score+=5}if(A.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){score+=10}if(A.match(/([a-zA-Z])/)&&A.match(/([0-9])/)){score+=15}if(A.match(/([!,@,#,$,%,^,&,*,?,_,~])/)&&A.match(/([0-9])/)){score+=15}if(A.match(/([!,@,#,$,%,^,&,*,?,_,~])/)&&A.match(/([a-zA-Z])/)){score+=15}if(A.match(/^\w+$/)||A.match(/^\d+$/)){score-=10}if(score<0){score=0}if(score>100){score=100}if(score<34){return badPass}if(score<68){return goodPass}return strongPass}function checkRepetition(A,B){res="";for(i=0;i<B.length;i++){repeated=true;for(j=0;j<A&&(j+i+A)<B.length;j++){repeated=repeated&&(B.charAt(j+i)==B.charAt(j+i+A))}if(j<A){repeated=false}if(repeated){i+=A-1;repeated=false}else{res+=B.charAt(i)}}return res}
