www.webdeveloper.com
Results 1 to 3 of 3

Thread: trying to output previous password attempts

  1. #1
    Join Date
    Nov 2003
    Location
    CT
    Posts
    6

    trying to output previous password attempts

    I am trying to write code that will allow the user 3 chances to enter a password. If on the 3rd chance they get it wrong, a page lets them know that they had 3 failed attempts, and outputs the 3 previous passwords they typed. The code below I got to work on the 4th attempt, that outputs the passwords fromt he prevoius 3, but the last one is blank. Is there a way to get it to work on the 3rd attempt, and to output what was entered in the 3rd final attempt?


    <%@ Language=VBScript %>
    <% Option Explicit %>
    <% Response.Buffer = True %>

    <%

    Dim strRealPass, strEnteredPass
    strRealPass = "cis382"
    strEnteredPass = Request.Form("txtPassword")

    If (strEnteredPass = strRealPass) Then
    Session("ValidUser") = "ForReal"
    Response.Redirect("MembersSecure.asp")
    ElseIf (strEnteredPass <> "cis382" and Request.Cookies("Login")("Attempts")) = 3 Then
    Response.Clear()
    Response.Write "<font size=4>Invalid Password.</font><br />"
    Response.Write "You had three failed logon attempts with the following passwords:<br />"
    Response.Write "First Attempt: " & Request.Cookies("Login")("Password1") & "<br />"
    Response.Write "Second Attempt: " & Request.Cookies("Login")("Password2") & "<br />"
    Response.Write "Third Attempt: " & Request.Cookies("Login")("Password3") & "<br />"

    Response.Cookies("Login").Expires = now



    Else
    If Request.Cookies("Login")("Attempts") = 0 Then
    Response.Cookies("Login")("Attempts") = 1
    Response.Cookies("Login")("Password1") = strEnteredPass
    ElseIf Request.Cookies("Login")("Attempts") = 1 Then
    Response.Cookies("Login")("Attempts") = 2
    Response.Cookies("Login")("Password2") = strEnteredPass
    ElseIf Request.Cookies("Login")("Attempts") = 2 Then
    Response.Cookies("Login")("Attempts") = 3
    Response.Cookies("Login")("Attempts") = strEnteredPass
    End If

    Response.Clear()
    Response.Write "<font size=4>Invalid Password." & "<br /></font>"
    Response.Write "<font size=4>You must be a valid member." & "</font>"
    End If
    %>

    <html>
    <body>
    <p>
    <font size="4"><b><a href="Login.html">Return to Log on.</a></b></font>
    </p>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    I dont understand the point of this. Why set several cookies just to show the user data which they have already seen?

    Also, the following snippet is a bit illogical. All you have to do is increment the value rather than coding a if-elseif tree.
    Code:
    If Request.Cookies("Login")("Attempts") = 0 Then 
       Response.Cookies("Login")("Attempts") = 1
       Response.Cookies("Login")("Password1") = strEnteredPass 
    ElseIf Request.Cookies("Login")("Attempts") = 1 Then  
       Response.Cookies("Login")("Attempts") = 2
       Response.Cookies("Login")("Password2") = strEnteredPass 
    ElseIf Request.Cookies("Login")("Attempts") = 2 Then 
       Response.Cookies("Login")("Attempts") = 3 
       Response.Cookies("Login")("Attempts") = strEnteredPass 
    End If
    It would be better written as follows:
    Code:
       dim i
       i = CInt(Request.Cookies("Login")("Attempts")) + 1
       Response.Cookies("Login")("Attempts") = i
       Response.Cookies("Login")("Password" & i) = strEnteredPass
    The reason your code was not working is because you have forgotten to change 'Attempts' to 'Password3' in your last elseif...

    Regards,
    Andrew Buntine.

  3. #3
    Join Date
    Nov 2003
    Location
    CT
    Posts
    6
    It's for an ASP class I am taking, sort of starting from the ground up I suppose. I finally got it working though, I didn't use the loop you created because I figured it out before I read this post. I'm sure your code is cleaner and involves less typing, but Im still new to this. But here's my code for the heck of it...Thank you for your ideas though.


    <%@ Language=VBScript %>
    <% Option Explicit %>
    <% Response.Buffer = True %>

    <%

    Dim strRealPass, strEnteredPass
    strRealPass = "cis382"
    strEnteredPass = Request.Form("txtPassword")

    If (strEnteredPass = strRealPass) Then
    Session("ValidUser") = "ForReal"
    Response.Redirect("MembersSecure.asp")

    ElseIf (strEnteredPass <> "cis382") Then
    Response.Clear()
    Response.Write "<font size=4>Invalid Password.</font><br />"
    Response.Write "<font size=4>You must be a valid member." & "</font><br />"

    If Request.Cookies("Login")("Attempts") = 0 Then
    Response.Cookies("Login")("Attempts") = 1
    Response.Cookies("Login")("Password1") = strEnteredPass
    ElseIf Request.Cookies("Login")("Attempts") = 1 Then
    Response.Cookies("Login")("Attempts") = 2
    Response.Cookies("Login")("Password2") = strEnteredPass
    ElseIf Request.Cookies("Login")("Attempts") = 2 Then
    Response.Cookies("Login")("Attempts") = 3
    Response.Cookies("Login")("Password3") = strEnteredPass

    Response.Write "You had three failed logon attempts with the following passwords:<br />"
    Response.Write "First Attempt: " & Request.Cookies("Login")("Password1") & "<br />"
    Response.Write "Second Attempt: " & Request.Cookies("Login")("Password2") & "<br />"
    Response.Write "Third Attempt: " & Request.Cookies("Login")("Password3") & "<br />"

    Response.Cookies("Login").Expires = now

    End If
    End If
    %>

    <html>
    <body>
    <p>
    <font size="4"><b><a href="Login.html">Return to Log on.</a></b></font>
    </p>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles