ASP login script works sometimes !?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default ASP login script works sometimes !?

    Hi folks !
    I finally got my login-page to run, but the thing is that it seems to
    live a life of its own. sometimes i can log in and sometimes not. the
    script should redirect me to diferent pages depending if i enter the
    username & password of an "admin" or a "user" and checkes one of them
    in the selectbox.
    i can sometimes login as an admin (some names in the db), but as a
    "user" i always end up in the "No user found" section (see code)
    All info is in the same table "Accounts" in the database.
    the code looks like this:

    ----------------------------------------------------------------------------
    here's the login.asp page

    <html>
    <head><title>login</title></head>
    <body>
    <p>Login</p> <br>
    <form method="post" action="verifyLogin.asp" >
    <table>
    <tr>
    <td align="right">Username: <input type=text name=username
    size=12></td>
    </tr>
    <tr>
    <td align="right">Password: <input type=password name=password
    size=12></td>
    </tr>
    <tr>
    <td align="right">Login type: <select name="logintype">
    <option value="admin">admin
    <option value="users">user
    </select></td>
    </tr>

    <td align="right"><input name="sendvalue" type="hidden"
    value="login"></td>
    <tr>
    <td><br></td>
    </tr>
    <tr>
    <td align="right"><input type="submit" value="login"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    -----------------------------------------------------------------------
    this is the verifyLogin.asp page:

    <!--#Include File="Connect.asp" --> //just the db-connection
    <html>
    <head><title>verifyLogin</title></head>
    <body>
    <%
    login = TRIM( Request.Form( "sendvalue" ) )

    username = TRIM( Request.Form( "username" ) ) 'saves formdata in
    local variables
    password = TRIM( Request.Form( "password" ) )
    usertype = TRIM( Request.Form( "logintype" ) )

    IF username = "" OR password = "" then 'if nothing is entered in the
    login form
    Response.Redirect "login.asp"
    END IF

    IF login <> "" THEN 'checks that formdata is sent

    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.ActiveConnection = Con

    SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    WHERE UserName=" &_
    "'" & username & "'" & "AND PassWord=" &_
    "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    RS.Open SQLstring

    IF RS.EOF THEN 'query returned nothing
    Response.Write "No user found"

    ELSE

    IF RS("UserName")=username AND RS("password")=password AND
    RS("UserType")="user" THEN

    Session("LoggedIn")=true
    Session("Pnr")=RS("Pnr")
    Response.Redirect "ProjectList.asp" 'if loged in as user

    ELSEIF RS("UserName")=username AND RS("PassWord")=password AND
    RS("UserType")="admin" THEN

    Session("LoggedIn")=true
    Session("Pnr")=RS("Pnr")
    Response.Redirect "admin.html"
    ELSE
    Response.Write "Wrong UserName or PassWord" 'if loged in as admin
    END IF

    END IF
    END IF

    RS.Close
    Con.Close
    Set RS = nothing
    Set Con = nothing
    %>
    </body>
    </html>
    ------------------------------------------------------------------------
    I checked all (hopefully) upper/lower case letters, so i don't think
    that is the problem.
    "No user found" should only be printed in case of EOF. but i get it
    most of the times, even when i enter user/pass that i know are in the
    database, and everytime as a "user".
    could really use some help...
    appreciate it...
    Fredrik/Sweden Guest

  2. Similar Questions and Discussions

    1. GD demo cgi script works on command line but not on webserver.
      Hi all, I recently installed GD version 2.34. The installation process went well, except that it said, it cannot find -liconv library. It also said...
    2. basic script member exchange no longer works....
      Hi all, This script used to work fine to create a rollover effect. on mouseEnter me sprite(me.spriteNum).member = member("rol") end
    3. script works from shell but not http
      #!/usr/bin/perl -w use strict; BEGIN{open(STDERR, ">./err.txt")} print "Content-Type: text/html\n\n"; foreach my $key (sort keys %ENV) { print...
    4. perl script works one machine but not others?
      Folks, I used my linux box running perl 5.8 to develop a small script that scans a list of directories and searches for files that dont have the...
    5. [PHP] Why wouldn't a simple script work on my server that works on other servers?
      * Thus wrote Dan Anderson (dan@mathjunkies.com): That is a sign that php isn't parsing them, so I would first make sure that my file extenstions...
  3. #2

    Default Re: ASP login script works sometimes !?

    Would something like this toward the top of the pages help at all?:

    <%
    Response.Expires = -1000 ' Make browser not cache pg.
    %>

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    [url]http://www.Bullschmidt.com[/url]
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt Guest

  4. #3

    Default Re: ASP login script works sometimes !?

    Hi Fredrik/Sweden,

    Your issue may have to do with not bracketing [password] and [username] in
    your SQL query.

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0309291322.515057c7@posting.google.c om...
    > this is the verifyLogin.asp page:
    >
    > Set RS = Server.CreateObject("ADODB.Recordset")
    > RS.ActiveConnection = Con

    >
    > SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    > WHERE UserName=" &_
    > "'" & username & "'" & "AND PassWord=" &_
    > "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    > RS.Open SQLstring


    SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    WHERE [UserName]=" &_
    "'" & username & "'" & "AND [PassWord]=" &_
    "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    RS.Open SQLstring





    >
    > IF RS.EOF THEN 'query returned nothing
    > Response.Write "No user found"
    >
    > ELSE
    >
    > IF RS("UserName")=username AND RS("password")=password AND
    > RS("UserType")="user" THEN
    You alreay know that rs("Username") = username, since you used that in your
    WHERE in your query.


    I suggest using this code:


    <%
    Dim rs, SQLString

    SQLString = "SELECT [Pnr],[UserType] FROM [Accounts] WHERE [UserName]='" &
    username & " AND [Password]='" & password & "'"
    Set rs = con.Execute(SQLString)
    If rs.EOF Then
    sUserType = 0
    Else
    sPnr = rs.Fields.Item(0).Value
    sUserType = rs.Fields.Item(1).Value
    End If
    rs.Close : Set rs = Nothing
    con.Close : Set con = Nothing


    Select Case True
    Case sUserType = 0
    Response.Write "User not found."
    Case sUserType = "admin"
    Session("LoggedIn") = True
    Session("Pnr") = sPnr
    Response.Redirect "admin.html"
    Case sUserType = "user"
    Session("LoggedIn") = True
    Session("Pnr") = sPnr
    Response.Redirect "ProjectList.asp"
    End Select

    %>

    Ray at work



    Ray at Guest

  5. #4

    Default Re: ASP login script works sometimes !?

    thanks...
    tried it but i still have the same problem !
    can't ever log in as 'user' !!??
    really strange...!
    Fredrik/Sweden Guest

  6. #5

    Default Re: ASP login script works sometimes !?

    I wonder what this is in reply to.

    Ray at work

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0309300723.11cdd82d@posting.google.c om...
    > thanks...
    > tried it but i still have the same problem !
    > can't ever log in as 'user' !!??
    > really strange...!

    Ray at Guest

  7. #6

    Default Re: ASP login script works sometimes !?

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0309291322.515057c7@posting.google.c om...
    > SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    > WHERE UserName=" &_
    > "'" & username & "'" & "AND PassWord=" &_
    > "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    Probably isn't the problem, but wouldn't it be "cleaner" to use:

    SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts" _
    & " WHERE UserName='" & username & "' _
    & " AND PassWord='" & password & "' _
    & " AND UserType='" & usertype & "'"

    There's less quotes and empersands to keep track of.


    --

    Phillip Windell [CCNA, MVP, MCP]
    [email]pwindell@wandtv.com[/email]
    WAND-TV (ABC Affiliate)
    [url]www.wandtv.com[/url]


    Phillip Windell Guest

  8. #7

    Default Re: ASP login script works sometimes !?

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message news:<O00U3B1hDHA.2512@TK2MSFTNGP09.phx.gbl>...
    > Hi Fredrik/Sweden,
    >
    > Your issue may have to do with not bracketing [password] and [username] in
    > your SQL query.
    >
    > "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    > news:a501fefe.0309291322.515057c7@posting.google.c om...
    >
    > > this is the verifyLogin.asp page:
    > >
    >
    > > Set RS = Server.CreateObject("ADODB.Recordset")
    > > RS.ActiveConnection = Con
    >
    >
    >
    > >
    > > SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    > > WHERE UserName=" &_
    > > "'" & username & "'" & "AND PassWord=" &_
    > > "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    > > RS.Open SQLstring
    >
    >
    >
    > SQLstring = "SELECT Pnr, UserName, PassWord, UserType FROM Accounts
    > WHERE [UserName]=" &_
    > "'" & username & "'" & "AND [PassWord]=" &_
    > "'" & password & "'" & "AND UserType=" & "'" & usertype & "'"
    > RS.Open SQLstring
    >
    >
    >
    >
    >
    >
    > >
    > > IF RS.EOF THEN 'query returned nothing
    > > Response.Write "No user found"
    > >
    > > ELSE
    > >
    > > IF RS("UserName")=username AND RS("password")=password AND
    > > RS("UserType")="user" THEN
    >
    > You alreay know that rs("Username") = username, since you used that in your
    > WHERE in your query.
    >
    >
    > I suggest using this code:
    >
    >
    > <%
    > Dim rs, SQLString
    >
    > SQLString = "SELECT [Pnr],[UserType] FROM [Accounts] WHERE [UserName]='" &
    > username & " AND [Password]='" & password & "'"
    > Set rs = con.Execute(SQLString)
    > If rs.EOF Then
    > sUserType = 0
    > Else
    > sPnr = rs.Fields.Item(0).Value
    > sUserType = rs.Fields.Item(1).Value
    > End If
    > rs.Close : Set rs = Nothing
    > con.Close : Set con = Nothing
    >
    >
    > Select Case True
    > Case sUserType = 0
    > Response.Write "User not found."
    > Case sUserType = "admin"
    > Session("LoggedIn") = True
    > Session("Pnr") = sPnr
    > Response.Redirect "admin.html"
    > Case sUserType = "user"
    > Session("LoggedIn") = True
    > Session("Pnr") = sPnr
    > Response.Redirect "ProjectList.asp"
    > End Select
    >
    > %>
    >
    > Ray at work

    Thanks a lot Ray !
    been reading your code (& used it), and it looks really neat ! and i
    actually understand it =) it should work fine ! just one problem
    left...i get the following error:

    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch: '[string: "admin"]'
    /VS_Files/verifyLogin2.asp, line 51

    Select Case True //line 51
    Case sUserType = 0
    Response.Write "User not found."
    Case sUserType = "admin"
    Session("LoggedIn") = True
    Session("Pnr") = sPnr
    Response.Redirect "admin.html"
    Case sUserType = "user"
    Session("LoggedIn") = True
    Session("Pnr") = sPnr
    Response.Redirect "ProjectList.asp"
    End Select

    tried ' instead of ", left "" out, etc etc...still the same...
    appreciate you taking time...
    thanks a lot !
    Fredrik
    Fredrik/Sweden Guest

  9. #8

    Default Re: ASP login script works sometimes !?

    Okay, try making these changes:

    ''code, code
    If rs.EOF Then
    sUserType = "0" '''added "'s

    ''code, code

    Case sUsertype = "0" '''added "'s


    Ray at work


    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0309301230.649e6015@posting.google.c om...
    >
    > Thanks a lot Ray !
    > been reading your code (& used it), and it looks really neat ! and i
    > actually understand it =) it should work fine ! just one problem
    > left...i get the following error:
    >
    > Error Type:
    > Microsoft VBScript runtime (0x800A000D)
    > Type mismatch: '[string: "admin"]'
    > /VS_Files/verifyLogin2.asp, line 51
    >
    > Select Case True //line 51
    > Case sUserType = 0
    > Response.Write "User not found."
    > Case sUserType = "admin"
    > Session("LoggedIn") = True
    > Session("Pnr") = sPnr
    > Response.Redirect "admin.html"
    > Case sUserType = "user"
    > Session("LoggedIn") = True
    > Session("Pnr") = sPnr
    > Response.Redirect "ProjectList.asp"
    > End Select
    >

    Ray at Guest

  10. #9

    Default Re: ASP login script works sometimes !?

    Ray at <%=sLocation%> wrote:
    > Okay, try making these changes:
    >
    > ''code, code
    > If rs.EOF Then
    > sUserType = "0" '''added "'s
    >
    > ''code, code
    >
    > Case sUsertype = "0" '''added "'s
    >
    Don't you mean:

    Select Case sUsertype
    Case "0"
    etc.


    Bob


    Bob Barrows Guest

  11. #10

    Default Re: ASP login script works sometimes !?

    Yes, I suppose that could make it into a typical select case if they're all
    the same data type now. Thank you Barrows.

    Ray at work

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:%230Eh8l5hDHA.2448@TK2MSFTNGP12.phx.gbl...
    > Ray at <%=sLocation%> wrote:
    > > Okay, try making these changes:
    > >
    > > ''code, code
    > > If rs.EOF Then
    > > sUserType = "0" '''added "'s
    > >
    > > ''code, code
    > >
    > > Case sUsertype = "0" '''added "'s
    > >
    > Don't you mean:
    >
    > Select Case sUsertype
    > Case "0"
    > etc.
    >
    >
    > Bob
    >
    >

    Ray at Guest

  12. #11

    Default Re: ASP login script works sometimes !?

    Bob, Ray & everybody else...
    THANK YOU A LOT !!!
    the scripts are now running perfectly !!!
    they're all part of my bachelors project. i'll be right back when i
    run into more problems, (that will be soon i guess =)
    i'm very grateful !!!
    Fredrik
    Fredrik/Sweden Guest

  13. #12

    Default Re: ASP login script works sometimes !?

    Outstanding. :]

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    > the scripts are now running perfectly !!!

    Ray at Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139