Here’s a really easy way to do password validation in Flash with AS3 using a few text fields and button component.
Here’s the code:
//password
var pass:String = "pass123";
//submit label
btn_submit.label = "Submit";
//event listeners
btn_submit.addEventListener(MouseEvent.CLICK, checkPassword);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
//set focus to input field
password_txt.stage.focus = password_txt;
//check input text field to pass string
function checkPassword(event:MouseEvent):void{
if(password_txt.text == pass){
feedback_txt.text = "Correct.";
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}else{
feedback_txt.text = "Incorrect.";
}
}
//enables keyboard enter key
function keyDownListener(e:KeyboardEvent) {
if (e.keyCode == Keyboard.ENTER){
checkPassword(null);
}
}
Nice !!!
I have a question.. is it possible to make it work for multiple users ?? a lot of users lets say 50,000 users..
also, im thinking maybe all the passwords can be in an external file.. txt or xml..
thanks and congrats !
hi roberto. yeah this isn’t the best way to do a password in flash, it’s just the easiest and most simple. i think if you needed 50,000 users, you’d have to do something more secure and hook up the usernames/passwords to a database with encryption.
putting all the passwords in an external file would be pretty simple, email me directly if you need some assistance, mike@marianomike.com
Hello,
I have a doubt. After password validation, how can i take the people to the next step of the site? Can you explain me that please? A code is missing i think so..
Many thanks
Gonçalo
This is great ! Easy and works out well. I have been searching quiet a while to find this, as most tutorials or scripts are related to AS 2 or earlier and this is the first one to work. Thx Mike !
thanks erik! glad it worked out for you!
nice!!
lucky to found this!it’s so cool!
i have a question,what’s the additional script if i want to move to the next frame if the password is correct?
thanks!:)
Hey Manuel, sorry it took me awhile to respond. To do that you could edit the checkPassword if statement, where if the password is correct, you could tell it to gotoAndStop(2). Also make sure you have a stop on the very first frame.