• 0

Display username on page after login


Question

2 answers to this question

Recommended Posts

  • 0

<%@ LANGUAGE="VBSCRIPT" %>

<% pageTitle = "Counter" %>

<% p_username = Request.form("p_username")

p_password = Request.form("p_password")

p_save = Request.form("p_save")

set unrealDB = Server.CreateObject("ADODB.Connection")

'unrealDB.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:\Chris\Website\UnrealNights\unreal.mdb"

unrealDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & SERVER.MapPath("..\unreal.mdb") & ";"

sqlText="select * from members where username='"&p_username &"'"

set userSet = unrealDB.Execute(sqlText)

if userSet.EOF then

'No such username, so the recordSet is empty

Response.Redirect "login.asp?retry=username"

else

'The username is good, now let's check the password

real_password = trim(userSet("password"))

if p_password = real_password then

'Password is good, too

Response.cookies("isLoggedInAs")("username") = p_username

Response.cookies("isLoggedInAs")("first_name") _

= userSet("first_name")

if p_save = "yes" then

Response.cookies("isLoggedInAs").expires =_

#December 31, 2999 00:00:00#

end if

else

'Username is good, but password is wrong

Response.Redirect "login.asp?retry=password"

end if

end if

%>

<% pageTitle = "Counter" %>

<!--#include file="pagetop.htm"-->

<hr noshade color="#BB6622" align="left">

<h1 align="left">You are now logged in.</h1>

<font size="5">Welcome back, <%= userSet("first_name")%>!

<% userSet.Close

set userSet = Nothing

unrealDB.Close

set unrealDB = Nothing

%> <br>

 </font><table width="75%" border="0" align="center">

<tr>

<td>You are currently logged in as: <font color="red"><%= Request.cookies("isLoggedInAs")("username")%></font> </td>

</tr>

</table>

<meta http-equiv="REFRESH" content="3; url=../index.asp" >

Now returning you to the main page in 3 seconds...<br>

<br>

<br>

<p>

<p>

<hr noshade color="#BB6622" align="left">

<h1 align="left"> </h1>

<!--#include file="pagebottom.txt"-->

</p>

</body>

</html>

Link to comment
Share on other sites

  • 0

what that does is open a connection to a database, requests the username stored in the database to that of a cookie on the pc, then shows it on the screen in the index.asp page if theres a match. if not it promps you to goto the login page to login.

some code might need to be changed, but you should see how i do it

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.