Currently Reading

Image of Derivatives Demystified: A Step-by-Step Guide to Forwards, Futures, Swaps and Options (The Wiley Finance Series)

Image of Working Effectively with Legacy Code (Robert C Martin)

Image of Coders at Work: Reflections on the Craft of Programming

Image of Succeeding with Agile: Software Development Using Scrum (Addison-Wesley Signature)

Recently Read

Image of Advanced Actionscript 3 with Design Patterns

Image of Test Driven: TDD and Acceptance TDD for Java Developers

Image of iPhone Advanced Projects (Books for Professionals by Professionals)

Image of Test Driven Development (The Addison-Wesley Signature Series)

Image of Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin)

Image of Refactoring: Improving the Design of Existing Code (Object Technology Series)

Image of The Secrets of Consulting: A Guide to Giving and Getting Advice Successfully

Image of UML 2 for Dummies

Image of Beginning iPhone 3 Development: Exploring the iPhone SDK

Image of ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques (Adobe Developer Library)


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> .