July 31, 2008

Password Strength Indicator in ActionScript 3

Filed under: Flex — Anthony @ 2:33 am

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

 
package co.uk.BetaDesigns.utils.string
{
  public class PasswordStrength
 {
    private static var _strength : Number = 0;
    private static var _regSmall : RegExp = new RegExp( /([a-z]+)/ );
    private static var _regBig : RegExp = new RegExp( /([A-Z]+)/ );
    private static var _regNum	: RegExp = new RegExp( /([0-9]+)/ );
    private static var _regSpecial : RegExp = new RegExp( /(\W+)/ );
 
   public static function checkStrength( password : String ) : Number
   {
			_strength = 0;
 
     		if( password.search( _regSmall ) != -1 )
     		{
     			_strength ++;
     		}
     		if( password.search( _regBig ) != -1 )
     		{
     			_strength ++;
     		}
     		if( password.search( _regNum ) != -1 )
     		{
     			_strength ++;
     		}
     		if( password.search( _regSpecial ) != -1 )
     		{
     			_strength ++;
     		}
     		return _strength;
    }
    public function PasswordStrength( se : SingletonEnforcer )
    {
	//Force it so the user can't get here;
    }
  }
}
class SingletonEnforcer{}
 

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .