login question

Discussion in 'ASP General' started by John Davis, Sep 18, 2003.

  1. John Davis

    John Davis Guest

    I put a little login (username and password textfields) in a web page, and
    once the user able to login, I want the username and password textfields
    will disappear, and replace with text "[UserName] has Login!]" in the same
    position.

    My question is how to make the username and password textfields disappear
    and replace with "[UserName] has Login!]" in the same position?
    This is the code I have done so far, but it has another problem: Even I
    first check if the length of username field is non-zero first, it still
    displays "Login Failed" before the user login. I guess it's the session
    problem but don't know how to fix it.

    <html>
    <head>
    <title>Login Form</title>
    </head>
    <body>
    <form action="login.asp" method="post">
    <table border="0">
    <tr>
    <td>User ID</td>
    <td><input type="text" name="username"></td>
    </tr>

    <tr>
    <td>Password</td>
    <td><input type="password" name="password"></td>
    </tr>
    </table>
    <input type="submit" value="submit">
    <input type="reset" value="reset">
    </form>


    <!-- #include file="dbConn.asp"-->
    <!-- METADATA TYPE="typelib"
    FILE="C:\Program Files\Common
    Files\System\ado\msado15.dll" -->


    <%
    If Len(Request.Form("username")) <> 0 Then
    Dim strusername, strpassword, sqlStmt, objRS
    strusername = Request.Form("username")
    strpassword = Request.Form("password")
    sqlStmt = "select * from [Password] where UserName = '" & strusername &
    "'" & _
    " And Password = " & "'" & strpassword & "'" & ";"
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    objRS.Open sqlStmt, strConnect ', adOpenStatic, adLockReadOnly,
    adCmdTable
    If objRS.EOF Then
    Response.Write "Login Failed"
    Else
    Response.Write "Login Success: " & _
    "UserName = " & strusername & "," & _
    "Password = " & strpassword
    End If
    End If
    %>
    </body>
    </html>


    please advise! thanks!
    john
    John Davis, Sep 18, 2003
    #1
    1. Advertising

  2. John Davis

    PB4FUN Guest

    Works fine here, only the text you want is not there.
    You Have this :
    Response.Write "Login Success: " & _
    "UserName = " & strusername & "," & _
    "Password = " & strpassword
    Seems you want to have this :
    Response.Write strUsername & " has login."
    Furthermore, you check the request.Form twice.
    Try this :
    strUsername = Trim(Request("Username"))
    If strUsername = "" Then
    'user did not fill in anything
    else
    'User did fill in something
    end if

    If you only check if the user has an account, so if there is a record
    containing the un and pw,
    try another query.
    Select Count(Username) From [Password] ..... etc.
    Now you allways have a record.
    If the user is in the db you will have objRS.Fields(0) = 1
    else objRS.Fields(0) will be 0
    Instead of adOpenStatic you can use adForwardOnly, is faster, and do not use
    the adCmdTable after it.

    Meindert, MCP

    > I put a little login (username and password textfields) in a web page, and
    > once the user able to login, I want the username and password textfields
    > will disappear, and replace with text "[UserName] has Login!]" in the same
    > position.
    >
    > My question is how to make the username and password textfields disappear
    > and replace with "[UserName] has Login!]" in the same position?
    > This is the code I have done so far, but it has another problem: Even I
    > first check if the length of username field is non-zero first, it still
    > displays "Login Failed" before the user login. I guess it's the session
    > problem but don't know how to fix it.
    >
    > <html>
    > <head>
    > <title>Login Form</title>
    > </head>
    > <body>
    > <form action="login.asp" method="post">
    > <table border="0">
    > <tr>
    > <td>User ID</td>
    > <td><input type="text" name="username"></td>
    > </tr>
    >
    > <tr>
    > <td>Password</td>
    > <td><input type="password" name="password"></td>
    > </tr>
    > </table>
    > <input type="submit" value="submit">
    > <input type="reset" value="reset">
    > </form>
    >
    >
    > <!-- #include file="dbConn.asp"-->
    > <!-- METADATA TYPE="typelib"
    > FILE="C:\Program Files\Common
    > Files\System\ado\msado15.dll" -->
    >
    >
    > <%
    > If Len(Request.Form("username")) <> 0 Then
    > Dim strusername, strpassword, sqlStmt, objRS
    > strusername = Request.Form("username")
    > strpassword = Request.Form("password")
    > sqlStmt = "select * from [Password] where UserName = '" & strusername

    &
    > "'" & _
    > " And Password = " & "'" & strpassword & "'" & ";"
    > Set objRS = Server.CreateObject("ADODB.RecordSet")
    > objRS.Open sqlStmt, strConnect ', adOpenStatic, adLockReadOnly,
    > adCmdTable
    > If objRS.EOF Then
    > Response.Write "Login Failed"
    > Else
    > Response.Write "Login Success: " & _
    > "UserName = " & strusername & "," & _
    > "Password = " & strpassword
    > End If
    > End If
    > %>
    > </body>
    > </html>
    >
    >
    > please advise! thanks!
    > john
    >
    >
    >
    >
    >
    PB4FUN, Sep 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Replies:
    0
    Views:
    427
    William F. Robertson, Jr.
    Jul 2, 2003
  2. Hermit Dave

    Forms Login Page Not Login Out

    Hermit Dave, Jan 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    452
    Hermit Dave
    Jan 13, 2004
  3. Nans
    Replies:
    2
    Views:
    20,068
    Martin Marinov
    Jun 17, 2004
  4. =?Utf-8?B?Z2FyaWJhbGRp?=
    Replies:
    2
    Views:
    4,899
    =?Utf-8?B?Z2FyaWJhbGRp?=
    Feb 25, 2005
  5. frekster
    Replies:
    1
    Views:
    919
    frekster
    Sep 14, 2005
Loading...

Share This Page