Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

login script using a while loop.

Status
Not open for further replies.

estesflyer

Programmer
Dec 19, 2000
284
US
ok, this isnt working, i mean, it works fine unless the user doesnt enter in the right username and/or password. it simply keeps displaying the alert.... just run the script and you will see what i mean


<script language=&quot;javascript&quot;>
<!--
var usrnm=&quot;user&quot;;
var pswrd=&quot;89563&quot;;
function login()
{
var usrnmtry=window.prompt(&quot;Plz enter your user name&quot;,&quot;John Doe&quot;);
var pswrdtry=window.prompt(&quot;Plz enter your password&quot;,&quot;mightyman&quot;);

while ((usrnmtry != usrnm) &amp;&amp; (pswrdtry != pswrd))
{
window.alert(&quot;Wrong username and/or password. Plz check your information, and try
again.&quot;);
usrnmtry;
pswrdtry;
}
}
//-->
</script>
<body onLoad=&quot;login()&quot;>

 
maybe this will work:

var usrnm=&quot;user&quot;;
var pswrd=&quot;89563&quot;;
function login()
{
var usrnmtry=window.prompt(&quot;Plz enter your user name&quot;,&quot;John Doe&quot;);
var pswrdtry=window.prompt(&quot;Plz enter your password&quot;,&quot;mightyman&quot;);

while ((usrnmtry != usrnm) &amp;&amp; (pswrdtry != pswrd))
{
window.alert(&quot;Wrong username and/or password. Plz check your information, and try again.&quot;);
usrnmtry=window.prompt(&quot;Plz enter your user name&quot;,&quot;John Doe&quot;);
pswrdtry=window.prompt(&quot;Plz enter your password&quot;,&quot;mightyman&quot;);
} jared@aauser.com
 
actually luciddream, im wanting to get it to work, i wanna learn javascript, not use it every once in a while, when your learning math, and you dont know how to subtract, you dont go ahead and add instead do you? dont think soo....

btw, it worked jared! it worked!
 
Yeah, one thing to make sure of is that when using a loop of any sort, you always update the test condition. Endless loops suck! And so does slavery, and abortion, and drugs and other stuff (forward all arguments to garbagedump@mail.com) jared@aauser.com
 
well, gee, estesflyer, you had a problem about getting stuck in an infinite loop, and from the code you were using, it looks like you wanted to use if instead. i've seen that you want to learn javascript... that's why i didn't bother going ahead and writing a script for you, and gave you a suggestion as to where you might want to look to fix your script. from the look of your code, it looked like you were using while for no reason. so, i suggested you to use if. sorry if that wasn't what you were looking for. adam@aauser.com
 
I hope that you plan on using this script for a secure site.
If so, I suggest you get into a server side language (perl, php, asp, etc) because you will have anyone who knows how to look at the source of your page able to enter the intended page.

You will find many people, including myself, willing to help you with learning a server side language.

-Vic vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
hey luciddream, sorry for being a bit harsh. was my fault. its all good eh? thx for the help tho! no, i am not going to use this script for anything,im just trying to get the hang of the while loop. :) thats all. yeh, i plan on learning a SSL sometime after I learn javascript. thx for the offer tho. I might take you up on that. anyway, thx all for your help! btw,if ya got icq, my number is 83807978

again, thx!

- Rusty
 
btw Jared, nice way of sneaking that moral lesson into your post!
:)

- Rusty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top