Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2012, 09:50 AM   PM User | #1
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
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>
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 09:57 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
newbiedude77 (02-21-2012)
Old 02-21-2012, 10:50 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 02-21-2012 at 10:52 AM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
newbiedude77 (02-21-2012)
Old 02-21-2012, 11:23 AM   PM User | #4
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 11:33 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by newbiedude77 View Post
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 02-21-2012, 11:37 AM   PM User | #6
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 11:40 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by newbiedude77 View Post
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.

Try counter --;
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 02-21-2012, 11:48 AM   PM User | #8
Co1dFusion
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 77
Thanks: 0
Thanked 12 Times in 11 Posts
Co1dFusion can only hope to improve
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.
Co1dFusion is offline   Reply With Quote
Users who have thanked Co1dFusion for this post:
newbiedude77 (02-21-2012)
Old 02-21-2012, 11:54 AM   PM User | #9
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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.

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>
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 12:11 PM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 02-21-2012 at 12:19 PM..
Philip M is offline   Reply With Quote
Old 02-21-2012, 12:41 PM   PM User | #11
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 12:42 PM   PM User | #12
Co1dFusion
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 77
Thanks: 0
Thanked 12 Times in 11 Posts
Co1dFusion can only hope to improve
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")
}
Co1dFusion is offline   Reply With Quote
Users who have thanked Co1dFusion for this post:
newbiedude77 (02-21-2012)
Old 02-21-2012, 02:36 PM   PM User | #13
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
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

Last edited by newbiedude77; 02-21-2012 at 02:41 PM..
newbiedude77 is offline   Reply With Quote
Old 02-21-2012, 02:39 PM   PM User | #14
Co1dFusion
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 77
Thanks: 0
Thanked 12 Times in 11 Posts
Co1dFusion can only hope to improve
Whats the problem with that?
Co1dFusion is offline   Reply With Quote
Old 02-21-2012, 02:42 PM   PM User | #15
newbiedude77
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
newbiedude77 is an unknown quantity at this point
nearly there

Quote:
Originally Posted by Co1dFusion View Post
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
newbiedude77 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:18 AM.


Advertisement
Log in to turn off these ads.