Password strength is a commonly used function, password strength of the implementation, in the Web is very good implementation, can be easily implemented using JavaScript method, currently because the project needs, to the mobile app also to achieve password strength, and at the same time to achieve the same function on both Android and iOS, Password complexity, no outside capital, lowercase letters, numbers and special symbols, and need to add repetition of the number of characters, etc., commonly used methods are the use of regular expressions.
Access to a lot of information, the Internet in the app-side password strength of the example is basically no (mobile phone QQ is called the Web page, pay no password complexity), and the Web and the app side of the three languages general, there is no way to only write their own, the web-side of the JavaScript method to rewrite, Android is the Java language is easy to rewrite, iOS with object-c language rewrite a little bit, three languages of the regular expressions are inconsistent, can only implement the requirements in different ways. Share it and make it perfect for everyone.
JavaScript Implementation methods:
Check the repetition of the password function checkpwdrepetition (Plen, str) {var res = ""; for (var i = 0; i < str.length; i++) {var repeated = true; for (var j = 0; J < Plen && (j + i + Plen) < Str.length; J + +) {repeated = repeated && (s Tr.charat (j + i) = = Str.charat (j + i + Plen)); } if (J < Plen) {repeated = false;} if (repeated) {i + = pLen-1; repeated = false; } else {res + = Str.charat (i); }} return res;};/ /Detect Password strength function checkpwdstrength (password) {var flag = 0; var score = 0; Password < 4 if (Password.length < 7) {flag = 3; return flag; }//Less than 9, and is a pure digit if (Password.length < 9 && Password.match (/^[0-9]*[1-9][0-9]*$/)) {flag = 4; return flag; }//Password length plus score + = Password.length * 4; Score + = (checkpwdrepetition (1, password). length-password.length) * 1; Score + = (CHECKPWDREpetition (2, password). length-password.length) * 1; Score + = (checkpwdrepetition (3, password). length-password.length) * 1; Score + = (checkpwdrepetition (4, password). length-password.length) * 1; Step1: The password has three digits if (Password.match (/(. *[0-9].*[0-9].*[0-9)/)) {score + = 5;} Step2: Password has two special characters if (Password.match (/(. *[!,@,#,$,%,^,&,*,?, _,~].*[!,@,#,$,%,^,&,*,?, _,~])) {score + = 5;} Step3: The password has uppercase and lowercase letters if (Password.match (/([a-z].*[a-z]) | ( [A-z].*[a-z])) {score + = 0;} Step4: Passwords have numbers and letters if (Password.match (/([a-za-z])/) && Password.match (/([0-9])/) {score + = 15;} STEP5: Passwords have numbers and special characters if (Password.match (/([!,@,#,$,%,^,&,*,?, _,~]) && Password.match (/([0-9])/)) {Score + = 15; }//STEP6: The password has letters and special characters if (Password.match (/([!,@,#,$,%,^,&,*,?, _,~]) && Password.match (/([a-za-z])/)) { Score + = 15; }//STEP7: The password is only numeric or only the letter if (Password.match (/^\w+$/) | | password.match (/^\d+$/)) {score-= 10;} Verifying 0 < score < if (Score < 0) {score = 0;} if (Score >) {score = 100;} if (Score < approx) {flag = 0;} else if (Score <) {flag = 1;} else {flag = 2; } if (Password.match (/([a-z].*[a-z]) | ( [a-z].*[a-z])/) && Password.match (/([0-9])/) {} else {flag = 5; return flag; } return flag;
Android Implementation method: Android Implementation method:
View Source
iOS Implementation method:
View Source
Multiple platforms for password strength (Javascript, Android, iOS)