![]() |
login form looking for help - please
Hello Im looking for help with my login form...So far I have coded that if I put in the correct password and username then I will getinto my site. I would like to have something whereby if I put in 3 failed attempts I get a message each time telling me how many attempts I have left and then no access.
After every failed attempt I want the textbox to clear aswel so i can enter in the next attempt......Thanks guys All help would be very helpful...I have tried this for a few days now with success ...... :) here is my cose so far <script language="javascript"> function passuser(form) { if (form.user.value=="tony" &&form.password.value=="hello") { window.alert("Hello tony") location='http://www.google.com' } } </script> </head> <body><center><br /> <form action="name" method="get"> <table width="300" height="200" border="1" cellpadding="5"cellspacing="5"> <tr> <th colspan="2" scope="col"bgcolor="#6699FF"><center>LOGIN FORM</center></th> </tr> <tr> <td width="120" align="center"> User Name</td> <td width="140"><label> <input type="text" name="user" id="user" /> </label></td> </tr> <tr> <td align="center">Password</td> <td><label> <input type="password" name="password" id="password" /> </label></td> </tr> <tr> <td align="center"><label> <input type="reset" name="cmdClear" id="cmdClear" value="Reset" /> </label></td> <td align="center"><label> <input type="submit" name="enter" id="log" value="Login" onclick="passuser(this.form)" /> </label></td> </tr> </table> </form> </center> </body> |
The security level of your application would be 0
So I assume this is some kind of homework? Otherwise you should forget about this before even implementing this ... except if it is for learning purposes (of how not to do it). Reason: Everyone with a browser (which is everyone visiting your page) can find the password with no effort. |
Set up a global variable counter = 3. Each failed attempt deduct 1 and show an alert (""You have " + counter " tries left");. If counter <=0 show alert ("You have run out of attempts"); and return false (stop execution).
This must be homework. Of course, after the 3 tries the user can simply reload the page and get another 3 goes. That is if he is too unknowing to use View Source. As devnull69 says, security quotient: 0. <form action="name" // what is that supposed to be? <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead. |
Quote:
Thanks very much for the replies...I understand what you are saying but could you show how do i code this.. Thank you |
Quote:
Make an effort to write the code yourself, and if you are then still really stuck come back for another hint. |
Quote:
|
Quote:
Try counter --; |
You should have a look at W3Schools and do their basic js tutorial.
I belive there are script similar to this on javascriptkits.com, so you should go there and learn from them. |
Quote:
Ok I got it working so far with my counter and it works good for the 3 failed attempts, Howwever My problem now is that when I enter in a correct username and password lets such say on my second attempt its says that I have access but it also gives the counter message saying that i only have 1 attempt left aswel....hmmmmm here is my code up to date... <script language="javascript"> var counter = 3 function passuser(form) { if (form.user.value=="trevor" &&form.password.value=="hello") { window.alert("Hello sir") location='http://www.google.com' } counter = counter - 1 if (counter ==2) { window.alert("Username or Password is incorrect - You have " +counter+ " tries left") } if (counter ==1) { window.alert("Username or Password is incorrect - You have " +counter+ " tries left") } if (counter ==0) { window.alert("Access Denied") } } </script> </head> <body><center><br /> <form action="name" method="get"> <table width="300" height="200" border="1" cellpadding="5"cellspacing="5"> <tr> <th colspan="2" scope="col"bgcolor="#6699FF"><center>LOGIN FORM</center></th> </tr> <tr> <td width="120" align="center"> User Name</td> <td width="140"><label> <input type="text" name="user" id="user" /> </label></td> </tr> <tr> <td align="center">Password</td> <td><label> <input type="password" name="password" id="password" /> </label></td> </tr> <tr> <td align="center"><label> <input type="reset" name="cmdClear" id="cmdClear" value="Reset" /> </label></td> <td align="center"><label> <input type="submit" name="enter" id="log" value="Login" onclick="passuser(this.form)" /> </label></td> </tr> </table> </form> </center> </body> |
Well that is the way you have arranged your code.
You want to show the message ("Username or Password is incorrect - You have " +counter+ " tries left") if (and only if) the log-on attempt fails. So use else if ...... There is no need for these if statements if (counter ==2) { if (counter ==1) { Simply show the message. You have counter = (2 1 0) tries left. if (counter ==0) should be if (counter <=0) However, if you choose to ignore the advice you have been given already, then expect little interest in helping you. Seriously, I have the idea that you are not cut out for this sort of thing. You need support from your teacher - not deceive him as to your skills level by getting others to do your homework. |
Quote:
|
You still need to change your script lots. Add semi-colons where you need them, and chage lan="javascript" to type="text/javascript"
Code:
if (form.user.value=="trevor" &&form.password.value=="hello") |
login form help
Hi and thnks for your reply. I got the login form working ok but when I put a wrong password into the form my form page shuts down when viewing it on the net. The process works fine when testing it out on dreamweaver. any ideas? am i missing some code. All help would be great thank you. Here is my code now up to date:
<script language="javascript"> var counter = 2 function passuser(form) { if (form.user.value=="john" &&form.password.value=="hello") { window.alert("Hello there") location='http://www.google.com' } else if (counter <=0) { window.alert("Access Denied") window.close() } else { window.alert("Username or Password is incorrect - You have " +counter+ " tries left") counter = counter - 1 return false; } } </script> </head> <body><center><br /> <form action="name" method="get"> <table width="300" height="200" border="1" cellpadding="5"cellspacing="5"> <tr> <th colspan="2" scope="col"bgcolor="#6699FF"><center>LOGIN FORM</center></th> </tr> <tr> <td width="120" align="center"> User Name</td> <td width="140"><label> <input type="text" name="user" id="user" onFocus="this.value=''" value="" /> </label></td> </tr> <tr> <td align="center">Password</td> <td><label> <input type="password" name="password" id="password" onFocus="this.value=''" value="" /> </label></td> </tr> <tr> <td align="center"><label> <input type="reset" name="cmdClear" id="cmdClear" value="Reset" /> </label></td> <td align="center"><label> <input type="submit" name="enter" id="log" value="Login" onclick="passuser(this.form)" /> </label></td> </tr> </table> </form> </center> </body |
Whats the problem with that?
|
nearly there
Quote:
<script language="javascript"> var counter = 2 function passuser(form) { if (form.user.value=="john" &&form.password.value=="hello") { window.alert("Hello there") location='http://www.google.com' } else if (counter <=0) { window.alert("Access Denied") window.close() } else { window.alert("Username or Password is incorrect - You have " +counter+ " tries left") counter = counter - 1 return false; } } </script> </head> <body><center><br /> <form action="name" method="get"> <table width="300" height="200" border="1" cellpadding="5"cellspacing="5"> <tr> <th colspan="2" scope="col"bgcolor="#6699FF"><center>LOGIN FORM</center></th> </tr> <tr> <td width="120" align="center"> User Name</td> <td width="140"><label> <input type="text" name="user" id="user" onFocus="this.value=''" value="" /> </label></td> </tr> <tr> <td align="center">Password</td> <td><label> <input type="password" name="password" id="password" onFocus="this.value=''" value="" /> </label></td> </tr> <tr> <td align="center"><label> <input type="reset" name="cmdClear" id="cmdClear" value="Reset" /> </label></td> <td align="center"><label> <input type="submit" name="enter" id="log" value="Login" onclick="passuser(this.form)" /> </label></td> </tr> </table> </form> </center> </body |
| All times are GMT +1. The time now is 08:00 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.