Login form with Timeout

Submitted by Karthikeyan on

Creating a asp login form which expires after particular time..
File 1 : login.asp
To show a login form. It creates a session variable t1 and sets the value to the current time (the page requested time)


<%@ Language=VBScript %>


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<CENTER> LOGIN</CENTER>
<FORM METHOD=POST ACTION="logtest.asp" id=form1 name=form1>
<TABLE WIDTH=300
 BGCOLOR=Khaki BORDERCOLOR=Aqua ALIGN=center BORDER=1 CELLSPACING=1 CELLPADDING=1>
  	<TR>
		<TD>USERNAME</TD>
		<TD><INPUT TYPE="text" NAME="uname"></TD>
	</TR>
	<TR>
		<TD>PASSWORD</TD>
		<TD><INPUT TYPE="password" NAME="pword"></TD>
	</TR>
	
</TABLE>
 <BR>
<CENTER> <INPUT NAME=BUTTON1 TYPE=SUBMIT VALUE="SUBMIT"> </CENTER>
</FORM>
<% session("t1") = time()%>

</BODY>
</HTML>

File 2: logtest.asp
To process the input from the login form. Time from session variable t1 is checked with the current time in server.

 
<%@ Language=VBScript %>
<%
username = Request.Form("uname")
password = Request.Form ("pword")
intime = session("t1")
outtime = TIME()
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<FONT face=Arial size=10>

<%diff=DateDiff("S", intime,outtime) 
if diff > 5 then
Response.Write "Sign in form Time out <br/> <a href=login.asp>Try Again</a>"
else

if username = "" or password = "" then
Response.Write "Enter your Username & Password <br/> <a href=login.asp>Go to Login Page</a>"
else
if username ="admin" and password="pass" then
session("loggedin") = true
session("uname") = username

Response.Write "Hi," &session("uname")&"<br>"

Response.Write "You have sucessfully logged in"
else
Response.Write "Username or Password Incorrect! <br/> <a href=login.asp>Try Again</a>"
end if
end if
end if
%>
</font>
</BODY>
</HTML>