SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help in Login page..

    Dear Someone who can help me,

    I have a problem. Whenever I input a correct username and password, the "car.asp" page appears. But whenever I put the wrong
    username and password, the "car.asp" still appears. what's wrong with my codes?..

    Here's my Code:

    <script type = "text/javascript">



    <%
    Sub CheckLogin
    Dim Conn, rs, sql


    set Conn = server.createobject("adodb.connection")
    Conn = "Provider=sqloledb;Data Source=datasource;" & _
    "Initial Catalog=catalog;User Id=user;Password=password;"
    Set rs = Server.CreateObject( "ADODB.Recordset" )

    sql = "SELECT * FROM CarInfo WHERE EmpID = '"&username&"'"

    rs.Open sql, Conn
    Session("UserLoggedIn") = "false"
    Do While Not rs.EOF
    If Request.myform("username") = rs("EmpID") And Request.myform("pword") = rs("Password") Then
    Session("UserLoggedIn") = "true"
    Exit Do
    End If
    rs.MoveNext
    Loop
    rs.Close
    Conn.Close



    If Session("UserLoggedIn") = "true" Then
    Response.Redirect ("password1.asp")
    Else
    Response.Write("Login Failed.<br><br>")
    ShowLogin
    End If


    End Sub

    %>



    </script>
    <body background="back.jpg">

    <form action= "car.asp" method="post" name="login" id="login>

    <h1><center> Company Name </center></h1>
    <h2><center> Project System </center></h2>
    <br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
    <p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
    <input type="submit" value="Login" onclick= "UserLoggedIn()">
    </center> </p>

    </form>


    </body>


    Kindly help me.. I really need help.

    Thank you,
    Paula

  2. #2
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If Session("UserLoggedIn") = "true" Then
    Response.Redirect ("password1.asp")


    the "password1.asp" is supposed to be "car.asp"

    sorry for that mistake.. help me please.. :l

  3. #3
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no "Request.myform" in ASP. Use "Request.Form"

  4. #4
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.. thank you for your reply..

    I now changed the Request.myform to Request.Form

    i also changed my whole codes..

    what happens is..
    the Password label, the password text box and the submit button appears on page load. I also tried to type a correct password on the password textbox, but nothing happens..


    here's my codes..


    <%
    Response.Expires = -1000 'Makes the browser not cache this page
    Response.Buffer = True 'Buffers the content so our Response.Redirect will work
    Session("UserLoggedIn") = ""
    If Request.Form("username")<>"" AND Request.Form("pword")<>"" Then
    CheckLogin
    Else
    ShowLogin
    End If

    Sub ShowLogin
    %>



    <body background="back.jpg">

    <form name="login" id="login>

    <h1><center> Company Name </center></h1>
    <h2><center> Project</center></h2>
    <br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
    <p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
    <input type="submit" value="Login">
    </center> </p>

    </form>


    </body>



    <%
    End Sub

    Sub CheckLogin
    Dim Conn, rs, sql


    set Conn = server.createobject("adodb.connection")
    Conn = "Provider=sqloledb;Data Source=datasource;" & _
    "Initial Catalog=catalog;User Id=user;Password=password;"
    Set rs = Server.CreateObject( "ADODB.Recordset" )

    sql = "SELECT * FROM CarInfo WHERE EmpID = '"&username&"'"

    Set rs = conn.execute(sql)

    rs.Open sql, Conn
    Session("UserLoggedIn") = "false"
    Do While Not rs.EOF
    If Request.form("username") = rs("EmpID") And Request.form("pword") = rs("Password") Then
    Session("UserLoggedIn") = "true"
    Exit Do
    End If
    rs.MoveNext
    Loop
    rs.Close
    Conn.Close



    If Session("UserLoggedIn") = "true" Then
    Response.Redirect "protectedpage.asp"
    Else
    Response.Write("Login Failed.<br><br>")
    ShowLogin
    End If


    End Sub

    %>

  5. #5
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using subroutine "Sub" I always invoke them with the explicit "Call" command

    so, instead of writing "CheckLogin" you should use "Call CheckLogin"

    and

    instead of "ShowLogin" , "Call ShowLogin"


    You should also use the "Trim" unction to insure blank character spaces are not being submitted.

    For example:

    instead of :

    Request.Form("username")

    use

    trim(Request.Form("username"))

  6. #6
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi Webber123456,

    I tried it..
    When I try to login, wether I input the correct username and password or not,
    the "Login Failed" message appears..

    Here's the code..

    <%
    Response.Expires = -1000
    Response.Buffer = True
    Session("UserLoggedIn") = ""
    If trim(Request.Form("username")) <> "" And trim(Request.Form("pword")) <> "" Then
    call CheckLogin
    Else
    call ShowLogin
    End If

    Sub ShowLogin
    %>



    <body background="back.jpg">

    <form name="login" method="post" action="password6.asp">

    <<h1><center> Company Name </center></h1>
    <h2><center> Project </center></h2>
    <br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
    <p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
    <input type="submit" value="Login" >
    </center> </p>

    </form>


    </body>



    <%
    End Sub

    Sub CheckLogin
    Dim Conn, rs, sql


    set Conn = server.createobject("adodb.connection")
    Conn.Open "Provider=sqloledb;Data Source=(local);" & _
    "Initial Catalog=catalog;User Id=user;Password=password;"


    sql = "SELECT EmpId, Password FROM table WHERE EmpId = '"&username&"'"

    Set rs = conn.execute(sql)

    Session("UserLoggedIn") = "false"
    Do While Not rs.EOF
    If trim(Request.form("username")) = rs("EmpId") And trim(Request.form("pword")) = rs("Password") Then
    Session("UserLoggedIn") = "true"
    Exit Do
    End If
    rs.MoveNext
    Loop
    rs.Close
    Conn.Close



    If Session("UserLoggedIn") = "true" Then
    Response.Redirect "protectedpage.asp"
    Else
    Response.Write("Login Failed.<br><br>")
    call ShowLogin
    End If


    End Sub

    %>



    Thank you,
    Paula

  7. #7
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please vereify this line of code


    sql = "SELECT EmpId, Password FROM table WHERE EmpId = '"&username&"'"

    I don't see where you have a value for "username"

    do a

    response.write(sql)
    response.end

    right after the sql statement to see if it is being generated correctly

    if so, comment out the response.end and do a check on the other values right after the execute statement in the checklogin sub to see if they are coming through correctly:

    response.write(trim(Request.form("username"))) & "<br>"
    response.write(trim(Request.form("pword"))) & "<br>"
    response.write(trim(rs("EmpId"))) & "<br>"
    response.write(trim(rs("Password") )) & "<br>"
    response.end

  8. #8
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again Webber123456,

    I this what you are telling me?..

    <%
    Response.Expires = -1000
    Response.Buffer = True
    Session("UserLoggedIn") = ""
    If Request.Form("username") <> "" And Request.Form("username") <> "" Then
    CheckLogin
    Else
    ShowLogin
    End If

    Sub ShowLogin
    %>



    <body background="back.jpg">

    <form name="login" method="post" action="password8.asp">

    <<h1><center> Company Name </center></h1>
    <h2><center> Project System </center></h2>
    <br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
    <p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
    <input type="submit" value="Login" >
    </center> </p>

    </form>


    </body>



    <%
    End Sub

    Sub CheckLogin
    Dim Conn, rs, sql


    set Conn = server.createobject("adodb.connection")
    Conn.Open "DSN=datasource;UID=id;PWD=pass;Database=database"


    sql = "SELECT * FROM CarInfo WHERE EmpId = '"&username&"'"

    Set rs = conn.execute(sql)

    Session("UserLoggedIn") = "false"
    Do While Not rs.EOF

    response.write(trim(Request.form("username"))) & "<br>"
    response.write(trim(Request.form("pword"))) & "<br>"
    response.write(trim(rs("EmpId"))) & "<br>"
    response.write(trim(rs("Password") )) & "<br>"
    response.end

    Exit Do

    rs.MoveNext
    Loop

    End If

    rs.Close
    Conn.Close



    End Sub

    %>

    Thank you,
    Paula

  9. #9
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the Code above is working..

  10. #10
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the code is working, and the values being displayed are correct as expected from the database with the user inputs supplied from the form, then you should have everything you need to be able to determine why the code is not producing the desired outcome.

    Compare the displayed results from the user inputs to the values returned from the database. If you have a match the code should redirect correctly. If there are no matches then the code should indicate login failed.

    the key to debugging this problem is verifying that the user inputs and database results are coming through correctly.

  11. #11
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Webber.. This codes are working.. thank you..

    I have another question..
    Can i use 2 form action in one form post?..

    Thanks,
    Paula

  12. #12
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paulapaupau View Post
    Hi Webber.. This codes are working.. thank you..

    I have another question..
    Can i use 2 form action in one form post?..

    Thanks,
    Paula
    No, only one form action can be applied.

  13. #13
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    What if I want to post the value of username to other pages?.. how am i going to get that value?..


    for example:

    <form name="login" method="post" action="password9.asp">
    'i would like to have action = "page1.asp"
    action = "page2.asp"



    <br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
    <p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
    <input name="btn" type="submit" value="Login" >
    </center> </p>

    </form>

  14. #14
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    once you submit the form to a page, then you will need to store that value, or some other id reference of the user, in a session variable, a database or a cookie so that it can be reused in other pages.


Bookmarks

Posting Permissions

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