CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   login form looking for help - please (http://www.codingforums.com/showthread.php?t=252164)

newbiedude77 02-21-2012 09:50 AM

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>

devnull69 02-21-2012 09:57 AM

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.

Philip M 02-21-2012 10:50 AM

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.

newbiedude77 02-21-2012 11:23 AM

Quote:

Originally Posted by Philip M (Post 1195666)
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.

Yes this is homework that im doing in college.
Thanks very much for the replies...I understand what you are saying but could you show how do i code this.. Thank you

Philip M 02-21-2012 11:33 AM

Quote:

Originally Posted by newbiedude77 (Post 1195679)
Yes this is homework that im doing in college.
Thanks very much for the replies...I understand what you are saying but could you show how do i code this.. Thank you

No, sorry. We will not do your homework for you (see forum rule #1.5). It is not really in your best interests that others do your all or most homework for you. Your teacher may gain a false and exaggerated idea of your programming capabilities and so not offer you the support you need.

Make an effort to write the code yourself, and if you are then still really stuck come back for another hint.

newbiedude77 02-21-2012 11:37 AM

Quote:

Originally Posted by Philip M (Post 1195682)
No, sorry. We will not do your homework for you (see forum rule #1.5). It is not really in your best interests that others do your all or most homework for you. Your teacher may gain a false and exaggerated idea of your programming capabilities and so not offer you the support you need.

Make an effort to write the code yourself, and if you are then still really stuck come back for another hint.

ok i understand but can you tell me how do i minus 1 from the counter each time....thats all I need to know...thank you

Philip M 02-21-2012 11:40 AM

Quote:

Originally Posted by newbiedude77 (Post 1195685)
ok i understand but can you tell me how do i minus 1 from the counter each time....thats all I need to know...thank you

To be candid, if you cannot deduct 1 from a counter then you ought to give up programming and consider taking up underwater motorcycling instead. :D

Try counter --;

Co1dFusion 02-21-2012 11:48 AM

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.

newbiedude77 02-21-2012 11:54 AM

Quote:

Originally Posted by Philip M (Post 1195686)
To be candid, if you cannot deduct 1 from a counter then you ought to give up programming and consider taking up underwater motorcycling instead. :D

Try counter --;

HaHA Some days I do feel like that packing it in :)
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>

Philip M 02-21-2012 12:11 PM

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.

newbiedude77 02-21-2012 12:41 PM

Quote:

Originally Posted by Philip M (Post 1195691)
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.

Cheers :thumbsup:

Co1dFusion 02-21-2012 12:42 PM

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")
{
window.alert("Hello sir")
location='http://www.google.com'
}
else{
window.alert("Username or Password is incorrect - You have " +counter+ " tries left")
}


newbiedude77 02-21-2012 02:36 PM

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

Co1dFusion 02-21-2012 02:39 PM

Whats the problem with that?

newbiedude77 02-21-2012 02:42 PM

nearly there
 
Quote:

Originally Posted by Co1dFusion (Post 1195726)
Whats the problem with that?

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


All times are GMT +1. The time now is 08:00 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.