MS ASP Code: Login Checking using Cookies
in place August 8, 2000, last modified August 8, 2000


index.htm(extraction)

enterance page

<UL>
<LI><A HREF= login.asp>Test Login</A>
<LI><A HREF= CleanCookie.asp>Clean the Cookie</A> /* clear the currently registered cookie */
</UL>

login.asp(extraction)

check whether the user client has a specific cookie, SaveLogin.
and If it exists pass the log free.

<%
if Request.Cookies("SavedLogin").HasKeys then
Response.Redirect "CheckLogin.asp?cookie=1"
end if
%>

<HTML>
<HEAD>
</HEAD>
<BODY>
/* else input the login and passwd */
<BR>please enter you login and passwd
<FORM ACTION="CheckLogin.asp" METHOD="POST" id=form1 name=form1>
<BR>login <INPUT TYPE=text name=login>
<BR>passwd <INPUT TYPE=password name= passwd>
<BR><INPUT TYPE=submit value=login id=submit1 name=submit1>
</FORM>

CheckLogin.asp(extraction)

If the cookie is exist then print out the passwd
and If not save cookie to clinet harddisk and set vaild period as 1 day.

<%
dim bLoginSaved

if Request.QueryString("cookie") =1 then
Response.Write("xxx Saved Passwd = " + CSTR(Request.Cookies("SavedLogin")("pw"))+" xxx")
else

Response.Cookies("SavedLogin")("pw") = Request.Form("passwd")
/* You can insert code for validation of passwd here */
Response.Cookies("SavedLogin").Expires = Date + 1 'The cookie is valild through 1 day
bLoginSaved = True
end if

%>

<HTML>
<HEAD>
</HEAD>
<BODY>
<% If bLoginSaved then %>
saving Loing information to a cookie<HR>
<% end if %>
Thank you, <STRONG><% = Request.Form("login") %></STRONG> for logging into the system.<P>
<A HREF=index.htm>To Test Login Home </A>
</BODY>
</HTML>

CleanCookie.asp(extraction)

Turn off (clean) the cookie setting today as the expire date.
Before the clean the program checks the existance.

<%
if Request.Cookies("SavedLogin").HasKeys then
Response.Cookies("SavedLogin").Expires = date
end if
Response.Redirect("index.htm")

%>


Knowledge & Engineering Databases (c) copyright Namchul Do, 2000