Login Needs to Generate Timestamp (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


jheun -> Login Needs to Generate Timestamp (5/5/2008 21:36:14)

I have developed a log in page that parses information from a database of user ids and passwords. I need that page to automatically send a timestamp, upon a successful login, of when that user logged in to a table within that database. Any help with sample code is greatly appreciated!!!




Spooky -> RE: Login Needs to Generate Timestamp (5/6/2008 16:01:15)

You would need to insert (as a minimum) the UserID, the tableID and the time into a new table so that multiple user records could be stored.

It should be as simple as a unique insert when the user enters the page within one session




DesiMcK -> RE: Login Needs to Generate Timestamp (5/6/2008 17:32:13)

I have used this code in the past

dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("UserLog.txt"),8,true)
f.WriteLine("UserName: " & strUserName1 & ", Password: VALID, Date and Time: " &MediumDate(FormatDateTime(Now)) & " - " & FormatDateTime(Now,4)) & ", IP=" & Request.ServerVariables("REMOTE_ADDR") & ", USER_AGENT=" & Request.ServerVariables("HTTP_USER_AGENT")
f.Close
set f=Nothing
set fs=Nothing

It writes the details to a text file called UserLog.txt

Desi




jheun -> RE: Login Needs to Generate Timestamp (5/11/2008 15:21:51)

Spooky,
Thank you for the information. I don't think I clearly explained my situation. I want the timestamp to be written to a table automatically upon the user login. Is there a script you can provide me with that does this?




Spooky -> RE: Login Needs to Generate Timestamp (5/11/2008 16:31:08)

Any asp script will do - all you are doing, is storing the date/time and the username in a new table at the same time they login.
The script would be processed within the same page.

eg
"INSERT INTO LOGIN_TABLE (Username,LoginTime) VALUES ('"&username&"', '"&Now()&"')




jheun -> RE: Login Needs to Generate Timestamp (5/11/2008 17:31:41)

Thanks, Spooky. At the risk of sounding like a total noob, I don't know how to write it so it works. I am sort of new to do this. Here is the code of the page:

<body bgcolor="#003366">
<%

'Connection String
Dim Conn
'Query to be executed
Dim SQLQuery
'Recordset
Dim rs
'StudentNo Of Logged in user
Dim UserName
'Password of User
Dim Password

'Getting information from submitted form
UserName = request.form("username")
Password = request.form("password")
RememberMe = request.form("rememberme")

'If not blank Username password submitted
if UserName <> "" or Password <> "" then
'Creating connection Object
set Conn=server.createobject("ADODB.Connection")
'Creating Recordset Object
set rs = Server.CreateObject("ADODB.Recordset")
'Initialising Provider String
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="
connStr = connStr + server.MapPath("fpdb/mhswimclub.mdb")

'Opening Connection to Database
Conn.open connStr

'Query to be executed
SQLQuery = "select * from members where lastname = '"&UserName&"' AND memberid = '"&Password&"'"
'Retrieving recordset by executing SQL
set rs=Conn.execute(SQLQuery)
'If no records retrieved
if rs.BOF and rs.EOF then
Response.Redirect "login.asp?username=" & UserName

else
'If remember me selected
if RememberMe = "ON" then
'Writing cookies permanently
Response.Cookies("UserName")=UserName
Response.Cookies("Password")=Password
Response.Cookies("UserName").Expires = Now() + 365
Response.Cookies("Password").Expires = Now() + 365
Response.Redirect "welcome.asp"
else
'writing cookies temporarily
Response.Cookies("UserName")=UserName
Response.Cookies("Password")=Password
Response.Redirect "welcome.asp"
end if
'Closing all database connections
Conn.Close
rs.close
set rs = nothing
set Conn = nothing
end if
else
'Invalid User
Response.Redirect "login.asp?UserName=blank"

end if
%>


--Thank you for your valuable time.




jheun -> RE: Login Needs to Generate Timestamp (6/5/2008 22:21:13)

PLEASE, ANYONE! Can anyone help me solve this? I need to know where to put the code Spooky gave me within the code above. The table I am trying to write to is Results within the login.mdb database.

I am literally begging [8|]




DesiMcK -> RE: Login Needs to Generate Timestamp (6/6/2008 5:55:20)

You will need to open a connection to login.mdb and execute the SQL. Can you do this on the login.asp page at the start?

Desi




jheun -> RE: Login Needs to Generate Timestamp (6/6/2008 22:34:00)

Thanks for the assist, Desi. The login.asp page directs itself to the page you see above. Here is the code for the login.asp page. I don't know if it is possible or not considering that the login page points to the page above. Do you know the answer to this?

<html>

<head>
<title>Home</title>
<style type="text/css">
.style1 {
font-family: Verdana;
font-size: large;
color: #FFFFFF;
}
.style2 {
border-style: solid;
border-width: 3px;
}
.style3 {
text-align: center;
}
.style4 {
text-align: center;
border-style: solid;
border-width: 1px;
}
.style5 {
color: #FFFFFF;
font-size: xx-large;
font-family: "Bookman Old Style";
}
</style>
</head>
<body style="background-color: #8D1D10; margin-left: auto; margin-right: auto">
<center>
<br>
<br>
<br>
<br>
<br>
<br>
<span class="style5">Mt. Holly Swim & Racquet Club</span><br>
<br>
<br>
<br>
<%
'StudentNo Of Logged in user
Dim Username
'Retrieving Username
Username=Request.QueryString("username")
'Invalid Username password
if UserName <> "" then
Response.Write "<font color='#FFAA00'>"
Response.Write "<font face='Verdana' size=2>"
Response.Write"Invalid UserName Password. Please Re-login"
Response.Write "</font></font>"
end if
%>
<form method="POST" action="verify.asp" name="form2">
<table cellspacing="1" bordercolor="#111111" id="AutoNumber1" style="width: 400px; height: 200px" class="style2">
<tr>
<td height="23" class="style1">User Name</td>
<td width="148" height="23">
<p align="center">
<font face="Verdana" color="#FFFFFF">
<input type="text" name="username" size="25" value=""><font size="2">
</font></font>
</td>
</tr>
<tr>
<td height="22" class="style1">Password</td>
<td width="148" height="22">
<p align="center"><font color="#FFFFFF" face="Verdana">
<input type="password" name="password" size="25"></font></td>
</tr>
<tr>
<td width="210" colspan="2" style="height: 22px">
<p align="center" style="width: 390px"> </td>
</tr>
<tr>
<td width="210" colspan="2" height="22" class="style4">
<p align="center" class="style3" style="width: 386px"><font face="Verdana" color="#FFFFFF">
<input type="submit" value="Verify Membership" name="B1"></font></td>
</tr>
</table>
</form>
</center>
</div>
</body>
</html>




DesiMcK -> RE: Login Needs to Generate Timestamp (6/7/2008 3:56:34)

You could try this:

At the start of welcome.asp add

<%

myDSN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/mhswimclub.mdb")

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN

Set oRS = conntemp.Execute("INSERT INTO LOGIN_TABLE (Username,LoginTime) VALUES ('"&username&"', '"&Now()&"')")

conntemp.execute(mySQL)

conntemp.close
set conntemp=nothing

%>

Desi




jheun -> RE: Login Needs to Generate Timestamp (6/7/2008 14:24:07)

Thanks Desi. I am getting an error that says "Field 'Results.username' cannot be a zero-length string." In looking at my database, it is not a zero length string. What are your thoughts on this?




DesiMcK -> RE: Login Needs to Generate Timestamp (6/7/2008 14:27:44)

try

Set oRS = conntemp.Execute("INSERT INTO LOGIN_TABLE (Username,LoginTime) VALUES ('"&Request.Cookies("username")&"', '"&Now()&"')")




jheun -> RE: Login Needs to Generate Timestamp (6/7/2008 14:32:06)

Nevermind my last question-fixed it. I get this error, though:

Microsoft JET Database Engine error '80040e0c'

Command text was not set for the command object.

/mhsrc/welcome2.asp, line 17


Here is the code you provided to me, which I have updated:

<%

myDSN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/userlogin.mdb")

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN

Set oRS = conntemp.Execute("INSERT INTO Results (Username,logtime) VALUES ('"&username&"', '"&Now()&"')")

conntemp.execute(mySQL)

conntemp.close
set conntemp=nothing

%>

Thanks, Desi!




DesiMcK -> RE: Login Needs to Generate Timestamp (6/7/2008 15:23:42)

Can you paste all the code for welcome2.asp please




jheun -> RE: Login Needs to Generate Timestamp (6/7/2008 15:25:44)

Additionally, the username is not being transferred from the verify page to this one, so the user's username is not being recorded.

There are three pages:
1. THe login page which has a form to house the username and password form fields. THis page goes to the...
2. The verify page which verfies the user against the membership database. A positive verification takes the user to the...
3. Welcome page, which is where you recommended I put the code snippet. The only issue here is that the user's username is not being passed from the verify page to this welcome page to be recorded in the userlogin database.

Again, thank you for your generous help!




jheun -> RE: Login Needs to Generate Timestamp (6/7/2008 15:26:16)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_LCID = 1033 %>
<meta http-equiv="Content-Language" content="en-us" />
<%
myDSN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("fpdb/userlogin.mdb")

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN

Set oRS = conntemp.Execute("INSERT INTO Results (Username,logtime) VALUES ('"&username&"', '"&Now()&"')")

conntemp.execute(mySQL)

conntemp.close
set conntemp=nothing
%>

<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_CharSet = "windows-1252"
FP_CodePage = 1252 %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Jump In</title>
<style type="text/css">
.style2 {
text-align: center;
font-size: x-large;
}
.style3 {
font-size: x-large;
color: #FFFFFF;
}
.style4 {
text-align: center;
}
.style6 {
text-align: center;
font-size: xx-large;
font-family: "Bookman Old Style";
color: #FFFFFF;
}
.style10 {
font-size: xx-large;
}
.style11 {
font-size: x-large;
color: #FFFFFF;
text-decoration: underline;
}
.style12 {
font-size: x-large;
}
</style>
</head>

<body style="background-color: #8D1D10">

<p class="style6"><strong>Welcome<br />
</strong><span class="style12">Thank You for Your Membership</span></p>
<p class="style6"><img alt="" src="images/img36.gif" /></p>
<div style="position: relative; width: 900; height: 100px; z-index: 1; margin-left: auto; margin-right: auto; left: 0px; top: 0px;" id="layer1" class="style4">
<table width="100%">
<tbody>
<tr>
<td class="style11"><strong>Important Messages:</strong></td>
</tr>
<!--webbot bot="DatabaseRegionStart" s-columnnames="ID,message" s-columntypes="3,203" s-dataconnection="mhsrcmessage" b-tableformat="TRUE" b-menuformat="FALSE" s-menuchoice s-menuvalue b-tableborder="FALSE" b-tableexpand="TRUE" b-tableheader="FALSE" b-listlabels="TRUE" b-listseparator="TRUE" i-listformat="0" b-makeform="FALSE" s-recordsource="message" s-displaycolumns="message" s-criteria s-order s-sql="SELECT * FROM message" b-procedure="FALSE" clientside suggestedext="asp" s-defaultfields s-norecordsfound="No records returned." i-maxrecords="256" i-groupsize="5" botid="0" u-dblib="_fpclass/fpdblib.inc" u-dbrgn1="_fpclass/fpdbrgn1.inc" u-dbrgn2="_fpclass/fpdbrgn2.inc" tag="TBODY" preview="<tr><td colspan="64" bgcolor="#FFFF00" width="100%"><font color="#000000">This is the start of a Database Results region.</font></td></tr>" startspan --><!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<script type="text/javascript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</script>
<% end if %>
<%
fp_sQry="SELECT * FROM message"
fp_sDefault=""
fp_sNoRecords="<tr><td colspan=1 align=""left"" width=""100%"">No records returned.</td></tr>"
fp_sDataConn="mhsrcmessage"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=5
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&ID=3&message=203&"
fp_iDisplayCols=1
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="40846" --><tr>
<td class="style3">
<strong>
<!--webbot bot="DatabaseResultColumn" s-columnnames="ID,message" s-column="message" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-MenuFormat preview="<font size="-1"><<</font>message<font size="-1">>></font>" startspan --><%=FP_FieldVal(fp_rs,"message")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="14728" --></strong></td>
</tr>
<!--webbot bot="DatabaseRegionEnd" b-tableformat="TRUE" b-menuformat="FALSE" u-dbrgn2="_fpclass/fpdbrgn2.inc" i-groupsize="5" clientside tag="TBODY" preview="<tr><td colspan="64" bgcolor="#FFFF00" width="100%"><font color="#000000">This is the end of a Database Results region.</font></td></tr><tr><td valign="middle" colspan="64"><nobr><input type="button" value=" |< "><input type="button" value=" < "><input type="button" value=" > "><input type="button" value=" >| "> [1/5]</nobr><br></td></tr>" startspan --><!--#include file="_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="62730" --></tbody>
</table>
</div>

<h3 class="style4"><img alt="" src="images/img36.gif" /></h3>
<h3 class="style4"><span class="style10"> </span><span class="style3">For your additional security, please Sign In or Sign Out</span></h3>

<p class="style2"><font color="#FFFFFF"><a href="verifylogin.asp">
<font color="#FFFFFF"><span class="style10">Sign In</span></font></a><span class="style10">   
</span> </font><a href="verifylogout.asp"><font color="#FFFFFF">
<span class="style10">Sign Out</span></font></a></p>

</body>

</html>




DesiMcK -> RE: Login Needs to Generate Timestamp (6/7/2008 15:51:17)

sorry - completely my fault. Remove the line:

conntemp.execute(mySQL)

Desi




jheun -> RE: Login Needs to Generate Timestamp (6/7/2008 16:18:11)

Desi!!!! You are the greatest! This is incredible. Thank you sooooo much for your assistance and perseverance. One day, I hope I can give back as much as I have taken.

It worked like a charm.

I had to set the database to accept zero-length string so that solved the problem with the INSERT INTO line for the 'username' value.

Again, thanks!




DesiMcK -> RE: Login Needs to Generate Timestamp (6/7/2008 18:23:38)

That's what this forum is about. It wasn't too long ago that I needed step by step guidance to everything. I found it here in this forum.

Just out of interest - when would the username be zero length?




jheun -> RE: Login Needs to Generate Timestamp (6/8/2008 17:06:30)

It would never be zero, but when I used the code you provided, I kept getting an error that told me that, so I set it that way. Of course, if I had tested from the login page and not the actual Welcome page, it might have not errored, but it won't be a problem anyhow since the user has to log in with a user name and password from the members database.

Thanks again. I am glad forums exist!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625