Connecting Tech Pros Worldwide Help | Site Map

login question

John Davis
Guest
 
Posts: n/a
#1: Jul 19 '05
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
Guest
 
Posts: n/a
#2: Jul 19 '05

re: login question


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
[color=blue]
> 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[/color]
&[color=blue]
> "'" & _
> " 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
>
>
>
>
>[/color]


Closed Thread


Similar ASP / Active Server Pages bytes