Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    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.

  • Users who have thanked devnull69 for this post:

    newbiedude77 (02-21-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,171
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    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.
    Last edited by Philip M; 02-21-2012 at 10:52 AM.

    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.

  • Users who have thanked Philip M for this post:

    newbiedude77 (02-21-2012)

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,171
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,171
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    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.

  • #8
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    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.

  • Users who have thanked Co1dFusion for this post:

    newbiedude77 (02-21-2012)

  • #9
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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>

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,171
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    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.
    Last edited by Philip M; 02-21-2012 at 12:19 PM.

    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.

  • #11
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #12
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    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")
    }

  • Users who have thanked Co1dFusion for this post:

    newbiedude77 (02-21-2012)

  • #13
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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.

  • #14
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Whats the problem with that?

  • #15
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •