AS3 Password Strength Meter


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. static public function
  2. fStart(
  3. vUserName : String,
  4. vInput : String
  5. ) : String
  6. {
  7. var vScore : int;
  8. // var vHasLetters : Array = vInput.match(/[a-zA-Z]+/);
  9. var vHasNumbers : Array = vInput.match(/[0-9]+/g);
  10. var vHasPunctuation : Array = vInput.match(/[^a-zA-Z0-9]+/);
  11. var vHasCasing : Array = vInput.match(/[a-z]+.*[A-Z]+|[A-Z]+.*[a-z]+/);
  12. var vResult : String;
  13.  
  14. if (vInput.length == 0) return "It's blank!";
  15.  
  16. vScore += (vInput.length < 7 ? 0 : 1);
  17. vScore += (vInput.length >= 12 ? 1 : 0);
  18. vScore += (vInput.toLowerCase() == vUserName.toLowerCase() ? 0 : 1);
  19. vScore += (vHasNumbers == null ? 0 : 1);
  20. vScore += (vHasNumbers != null && vHasNumbers.length <= 4 ? 0 : 1);
  21. vScore += (vHasPunctuation == null ? 0 : 1);
  22. vScore += (vHasPunctuation != null && String(vHasPunctuation).length <= 2 ? 0 : 1);
  23. vScore += (vHasCasing == null ? 0 : 1);
  24. vScore += (vHasCasing != null && String(vHasCasing).length <= 2 ? 0 : 1);
  25.  
  26. switch (vScore)
  27. {
  28. case 0:
  29. case 1:
  30. case 2:
  31. case 3:
  32. vResult = "Weak";
  33. break;
  34. case 4:
  35. case 5:
  36. case 6:
  37. case 7:
  38. vResult = "Medium";
  39. break;
  40. case 8:
  41. case 9:
  42. vResult = "Strong";
  43. break;
  44. }
  45. return vResult;
  46. }

URL: http://simplistika.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.