Be a Supporter!

User Login Problem

  • 229 Views
  • 9 Replies
New Topic Respond to this Topic
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
User Login Problem 2013-10-21 19:32:03 Reply

Here is the script
stop();

//Declear Array
var UserArray:Array = [];
var PassArray:Array = [];

//Declear Flag
var Flag:Boolean = false;

//Declear Your URLLoader
var UserDataLoader:URLLoader = new URLLoader ;

//Declaer Your URLLoade as to read as Variable
UserDataLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

//Declear EventListener for your URLLoader
UserDataLoader.addEventListener(Event.COMPLETE,onLoaded);
function onLoaded(e:Event):void
{

UserArray = e.target.data.Username;
PassArray = e.target.data.Password;
trace("Your File have been Loaded");

}

//Load your file
UserDataLoader.load(new URLRequest("Users_Password_Data.txt"));

//Declear EventListener for your button;
btn_Login.addEventListener(MouseEvent.CLICK,LoginEvent);

//Declear Function for your EventListener;
function LoginEvent(e:MouseEvent):void
{
trace("The Login Button was clicked");
for (var i:Number=0; i<=UserArray.length || Flag == true; i++)
{
trace(UserArray[i]);
trace(user_textbox.text);
trace(PassArray[i]);
trace(pass_textbox.text);
trace(Flag);

if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}
i++;

}

if (Flag== true){
gotoAndStop(2);

}
}

this.btn_Login.removeEventListener(Event.ENTER_FRAME,LoginEvent);

The script work fine!

but it never satisfy this condition:

if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}

even though the value are equal! any help to make this condition work?!

text value:

Username=A
&Username=B
&Username=C
&Username=D
&Username=E

&Password=1
&Password=2
&Password=3
&Password=4
&Password=5

A with 1
B with 2
C with 3
D with 4
E with 5

kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to User Login Problem 2013-10-22 08:31:29 Reply

If the flag becomes true in your for loop, it will run infinitely.


BBS Signature
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to User Login Problem 2013-10-22 10:09:45 Reply

At 10/22/13 08:31 AM, kkots wrote: If the flag becomes true in your for loop, it will run infinitely.

why it will run infinitely?! wasn't the for loop tells me if the condition is satisfied then exit the loop?!

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Online!
Forum Stats
Supporter
Level 16
Game Developer
Response to User Login Problem 2013-10-22 11:08:24 Reply

At 10/22/13 10:09 AM, A-Genius wrote:
At 10/22/13 08:31 AM, kkots wrote: If the flag becomes true in your for loop, it will run infinitely.
why it will run infinitely?! wasn't the for loop tells me if the condition is satisfied then exit the loop?!

Put the flag part in the loop instead of in the for statement, you're probably confusing yourself.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to User Login Problem 2013-10-22 13:51:56 Reply

At 10/22/13 10:09 AM, A-Genius wrote: wasn't the for loop tells me if the condition is satisfied then exit the loop?!

Just set a breakpoint and debug your code. Stop the guesswork.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to User Login Problem 2013-10-22 22:13:20 Reply

At 10/22/13 11:08 AM, MSGhero wrote: Put the flag part in the loop instead of in the for statement, you're probably confusing yourself.
At 10/22/13 01:51 PM, milchreis wrote: Just set a breakpoint and debug your code. Stop the guesswork.

Thanks for the help everyone!

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to User Login Problem 2013-10-22 22:59:23 Reply

At 10/22/13 11:08 AM, MSGhero wrote:

I fixed the previous but that didn't change the fact that the actual problem is that:

if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
{
Flag = true;
}

this condition never satisfied ! even thought the value of the textboxs equal to the arrays

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to User Login Problem 2013-10-22 23:07:28 Reply

When you change your code, post the new code.
Make sure you use the code tags this time.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to User Login Problem 2013-10-23 01:30:44 Reply

At 10/22/13 11:07 PM, milchreis wrote: When you change your code, post the new code.
Make sure you use the code tags this time.
stop();

//Declear Array
var UserArray:Array = [];
var PassArray:Array = [];

//Declear Flag
var Flag:Boolean = false;

//Declear Your URLLoader
var UserDataLoader:URLLoader = new URLLoader  ;

//Declaer Your URLLoade as to read as Variable
UserDataLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

//Declear EventListener for your URLLoader
UserDataLoader.addEventListener(Event.COMPLETE,onLoaded);
function onLoaded(e:Event):void
{

	UserArray = e.target.data.Username;
	PassArray = e.target.data.Password;
	trace("Your File have been Loaded");


}

//Load your file
UserDataLoader.load(new URLRequest("Users_Password_Data.txt"));


//Declear EventListener for your button;
btn_Login.addEventListener(MouseEvent.CLICK,LoginEvent);

//Declear Function for your EventListener;
function LoginEvent(e:MouseEvent):void
{
	trace("The Login Button was clicked");	
	for (var i:Number=0; i<=UserArray.length; i++)
	{
		trace(Flag);

		
		if (user_textbox.text == UserArray[i] && pass_textbox.text == PassArray[i])
		{
				Flag = true;
		}
		i++;
	
	}
	
	
	if (Flag== true){
		gotoAndStop(2);

	}
}
				


this.btn_Login.removeEventListener(Event.ENTER_FRAME,LoginEvent);
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to User Login Problem 2013-10-23 11:31:07 Reply

Ok, now we can take a look.

First of all: Do you know that this is not secure at all?
Client side user authentication tends to be insecure.

What's the point of the Flag variable besides what it does in your code?
If you want to check the condition and goto a different frame, just do that. No need to set flag variables that aren'T used elsewhere.
Give proper names to your variables.

You for loop seems to be wrong. (It is)
This is really fundamental stuff.
Take that for loop, just the for loop without anything inside it and put it into an empty project.
Trace i on every iteration (or use the debugger) and think about if is the way it's meant to be. (It's not)

Why do you remove a listener for ENTER_FRAME Event that is never added?

Why do you increment i in the loop?