Class for measuring or checking the safety or strength of a password in flash as3
This movie requires Flash Player 9
[download id=»9″ format=»2″]
Clase TestKey
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//Code developed by xavirobot.com 2011(simplified to infinity and beyond) package { final public class TestKey { //get Points public static function points(key:String):int { //Check password strength by points //Symbols are not counted return (key.length >= 8 ? 1 : 0)+ (key.length >= 12 ? 1 : 0)+ (key.match(/[a-z]+/)? 1 : 0)+ (key.match(/[A-Z]+/)? 1 : 0)+ (key.match(/[0-9]+/)? 1 : 0); /* Return 0 -> No Password :( Return 1 -> Very Low = Red Return 2 -> Low = Red Return 3 -> Medium/Low = Orange Return 4 -> Medium(Good) = Yellow Return 5 -> High = Green */ }//End getPoints //get validate value public static function validate(key:String):int { //Check if the password is good //Requirements, minimum 8 characters, one lowercase letter, one uppercase letter, one number and no symbols return (!key.match(/[a-z]+/)?0:(!key.match(/[A-Z]+/)?-1:(!key.match(/[0-9]+/)?-2:(key.length<8?-3:(key.match(/[^a-zA-Z0-9]+/)?-4:1))))); /* Return 1 -> valid password :) Return 0 -> Bad password, Please enter at least one lower case. Return -1 -> Bad password, Please enter at least one uppercase. Return -2 -> Bad password, Please enter at least one number. Return -3 -> Bad password, Please enter at least 8 characters. Return -4 -> Bad password, Symbols are not allowed. */ }//End validate }//End Class }//End Package |
Ejemplo de uso de la clase en el stage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import TestKey; txt_input.maxChars = 12; bar.width = 0; txt_input.addEventListener(Event.CHANGE,onChange); function onChange(e:Event):void { var points:int = TestKey.points(e.target.text); if (points == 1) { out.text = "Very Low"; bar.transform.colorTransform = new ColorTransform(0,0,0,1,255,-255,-255,1); } else if (points == 2) { out.text = "Low"; bar.transform.colorTransform = new ColorTransform(1,1,1,1,-100,-255,-255); } else if (points == 3) { out.text = "Medium/Low"; bar.transform.colorTransform = new ColorTransform(0,0,0,1,255,149,-255); } else if (points == 4) { out.text = "Medium(Good)"; bar.transform.colorTransform = new ColorTransform(0,0,0,1,255,255,-255); } else if (points == 5) { out.text = "High(Good)"; bar.transform.colorTransform = new ColorTransform(0,0,0,1,-255,255,-255); } bar.width = Math.floor((points / 5)*100); } validate.addEventListener(MouseEvent.CLICK,onClick); function onClick(e:Event):void { var res:int = TestKey.validate(txt_input.text); log.text = ""; if (res == 1) { log.text = "Contraseña valida"; } else if (res == 0) { log.text = "La contraseña debe contener como minimo una minuscula"; } else if (res == -1) { log.text = "La contraseña debe contener como minimo una mayuscula"; } else if (res == -2) { log.text = "La contraseña debe contener como minimo un numero"; } else if (res == -3) { log.text = "La contraseña debe contener como minimo 8 caracteres"; } else if (res == -4) { log.text = "No se permiten simbolos ni signos de puntuacion"; } } |
Social Report xavirobot