Ask a Question related to ASP Database, Design and Development.
-
Fredrik/Sweden #1
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
-
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... -
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 -
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... -
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... -
[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... -
Bullschmidt #2
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
-
Ray at #3
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
You alreay know that rs("Username") = username, since you used that in your>
> 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
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
-
Fredrik/Sweden #4
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
-
Ray at #5
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
-
Phillip Windell #6
Re: ASP login script works sometimes !?
"Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
news:a501fefe.0309291322.515057c7@posting.google.c om...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 & "'"
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
-
Fredrik/Sweden #7
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
-
Ray at #8
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
-
Bob Barrows #9
Re: ASP login script works sometimes !?
Ray at <%=sLocation%> wrote:
Don't you mean:> Okay, try making these changes:
>
> ''code, code
> If rs.EOF Then
> sUserType = "0" '''added "'s
>
> ''code, code
>
> Case sUsertype = "0" '''added "'s
>
Select Case sUsertype
Case "0"
etc.
Bob
Bob Barrows Guest
-
Ray at #10
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:> Don't you mean:> > Okay, try making these changes:
> >
> > ''code, code
> > If rs.EOF Then
> > sUserType = "0" '''added "'s
> >
> > ''code, code
> >
> > Case sUsertype = "0" '''added "'s
> >
>
> Select Case sUsertype
> Case "0"
> etc.
>
>
> Bob
>
>
Ray at Guest
-
Fredrik/Sweden #11
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
-
Ray at #12
Re: ASP login script works sometimes !?
Outstanding. :]
"Fredrik/Sweden" <fredda054@hotmail.com> wrote in message> the scripts are now running perfectly !!!
Ray at Guest



Reply With Quote

