BetaDesigns( Blog ) Flex and Component Development

31Jul/081

Password Strength Indicator in ActionScript 3

I needed to build a simple Password Strength indicator much like the ones you find on google registration pages. Using some simple RegExp ( Regualar Expressions ) it wasn't that hard.
Below is a simple example that uses the class to display the security level as well as updating a HBox to show a visual indication of the quality of your password.
The crieteria for the regular expressions are to check Capital letters, standard letters, numbers and none word characters to build up the quality level Right click to view source

  1. package co.uk.BetaDesigns.utils.string
  2. {
  3. public class PasswordStrength
  4. {
  5. private static var _strength : Number = 0;
  6. private static var _regSmall : RegExp = new RegExp( /([a-z]+)/ );
  7. private static var _regBig : RegExp = new RegExp( /([A-Z]+)/ );
  8. private static var _regNum : RegExp = new RegExp( /([0-9]+)/ );
  9. private static var _regSpecial : RegExp = new RegExp( /(\W+)/ );
  10.  
  11. public static function checkStrength( password : String ) : Number
  12. {
  13. _strength = 0;
  14.  
  15. if( password.search( _regSmall ) != -1 )
  16. {
  17. _strength ++;
  18. }
  19. if( password.search( _regBig ) != -1 )
  20. {
  21. _strength ++;
  22. }
  23. if( password.search( _regNum ) != -1 )
  24. {
  25. _strength ++;
  26. }
  27. if( password.search( _regSpecial ) != -1 )
  28. {
  29. _strength ++;
  30. }
  31. return _strength;
  32. }
  33. public function PasswordStrength( se : SingletonEnforcer )
  34. {
  35. //Force it so the user can't get here;
  36. }
  37. }
  38. }
  39. class SingletonEnforcer{}
  40.  
Be Sociable, Share!
Comments (1) Trackbacks (0)
  1. Very handy password util. Good post


Leave a comment

(required)

No trackbacks yet.