View Full Version : submit password
I want to create a text field, where the user has a password, upon verefication it proceeds to either go to a url or play a swf(I know how to do that part.)
I just need a simple explanation or a tutorial that talks about verifying user input such as id and pasword.
I can do this simply with javascript or PHP, just not flash. I can(as that I mean try) to make it with PHP, a password(ecrypted) that will use ajax to send the data and if the data is correct then display the flash file, if it's not then go to the URL.
Medyman
06-28-2008, 09:10 PM
I want to create a text field, where the user has a password, upon verefication it proceeds to either go to a url or play a swf(I know how to do that part.)
I just need a simple explanation or a tutorial that talks about verifying user input such as id and pasword.
What level of user authentication are you wanting to do here? Is this linked to a user database (e.g. mySQL)?
If so, you're going to have to use a combination of PHP and AS for it to work. Flash can't directly connect to MySQL, but it can communicate with PHP. So, the workflow here would be to send whatever is entered through the input field to a PHP script that would authenticate the user and then reply back to Flash with some sort of signal (probably through a variable).
If it's just a matter of a few usernames that you want to hard code, then we're just talking some basic conditionals:
AS3:
submit.addEventListener(MouseEvent.CLICK, authenticate);
function authenticate(e:MouseEvent):void {
if(username.text == "John") {
if(password.text == "Doe") }
gotoAndPlay("successful_login");
}
else {
status.text = "Incorrect Password";
}
}
else {
status.text = "Incorrect Username";
}
}
AS2:
submit.onRelease = function() {
if(username.text == "John") {
if(password.text == "Doe") }
gotoAndPlay("successful_login");
}
else {
status.text = "Incorrect Password";
}
}
else {
status.text = "Incorrect Username";
}
}
username and password are instance names for input fields. status would be another dyanamic text field that could display errors. Of course, if you're going to hard code more, you'll probably want to loop through an array or use switch/case syntax instead of repeating code blocks.
Let me know if there is server-side scripting involved. I'll post an small example of how that's done if you need.
1083: Syntax error: rightbrace is unexpected.
then it tells me the else is unexpected
bummer.
Medyman
06-30-2008, 07:49 PM
1083: Syntax error: rightbrace is unexpected.
then it tells me the else is unexpected
bummer.
That's what I get for typing directly into the forum. You might have figured it out as it's only a simple typo, but this is the correct way of writing that code:
submit.addEventListener(MouseEvent.CLICK, authenticate);
function authenticate(e:MouseEvent):void {
if(username.text == "John") {
if(password.text == "Doe") {
gotoAndPlay("successful_login");
}
else {
status.text = "Incorrect Password";
}
}
else {
status.text = "Incorrect Username";
}
}
I accidentally typed a right brace (}) instead of a left brace ({).
Other way(another type):
I used a right brace ({) instead of a left brace (}).
Just a tip: Don't tell people when there password is wrong, say username or password is wrong.
Medyman
06-30-2008, 07:56 PM
Other way(another type):
Just a tip: Don't tell people when there password is wrong, say username or password is wrong.
Man, i'm really out of it today. Thanks Nile. Fixed it in the orig. post.
As for your suggestion -- I agree. I just added that so that it would be obvious what was happening there without using comments :)
Teheheehe, I didn't see the mix up between the names of the braces, but you said you accidently used a { instead of a }, but you really used a } instead of a {.
:D
While I was messing around I came up with:
stop();
var confirmPtI:Number=10;
var confirmPtII:Number=10;
submit.addEventListener(MouseEvent.CLICK, authenticate);
function authenticate(e:MouseEvent):void {
if(username.text == "Muppet")
{confirmPtI=20;}
if(password.text == "Chef")
{confirmPtII=20;}
if ( confirmPtI<15 && confirmPtII<15){gotoAndPlay("no");}else {gotoAndPlay("start");}
}
I can set it up to make a distinction between user or pwd incorrect. I know using variable looks silly but I hate getting caught up with {} mistakes -I do it too much to even realize whether I did that or made a more important coding error.
Now, can anyone give me a rundown on getting this to work with SQL, as in doing something more advanced?
Such as:
User creates account:
User logs in -->validate
User logs incorrectly three times -selects one of two choices: create an account, OR forgot user name and pwd.
I any good reading material on the subject also?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.