Cookie 'Remember me' Login Script
Below is the code for a file called 'login.asp'. On successful
login the visitor is redirected to the second page 'admin.asp'.
Login.asp
<% Response.Buffer = True
Session("BlnAdministrator")=false
sUsername="codefixer"
sPassword="codefixer"
%>
<html>
<head>
<title>Cookie Login Script</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<%
If Request.Form<>"" Then
If Request.form("checkbox") ="1" Then
Response.Cookies("UsernameCookie") = Request.Form("txtUsername")
Response.Cookies("PasswordCookie") = Request.Form("txtPassword")
Response.Cookies("RememberMeCookie") = "1"
Response.Cookies("UsernameCookie").expires = Now() + 60
Response.Cookies("PasswordCookie").expires = Now() + 60
Response.Cookies("RememberMeCookie").expires = Now() + 60
Else
Response.Cookies("RememberMeCookie") = ""
Response.Cookies("UsernameCookie") = ""
Response.Cookies("PasswordCookie") = ""
End If
CheckLoginForm
Else
ShowLoginForm
End If
Sub ShowLoginForm
%>
<div align="center"> <br>
<form name="form1" action="<%=Request.ServerVariables("SCRIPT_NAME")%>"
method="post">
<table width="50%" border="1" align="center"
cellpadding="4" cellspacing="0" bordercolor="#6185C1"
bgcolor="EEF3FB">
<tr>
<td height="112" valign="top">
<table width='100%' border="0" cellpadding="3">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="45%">Username : </td>
<td width="54%"> <input value="<%= Request.Cookies("UsernameCookie")
%>" name="txtUsername" type="text">
</td>
</tr>
<tr>
<td width="45%">Password : </td>
<td width="54%"> <input value="<%= Request.Cookies("PasswordCookie")
%>" name="txtPassword" type="password">
</td>
</tr>
<tr>
<td width="45%"> </td>
<td width="54%"> <input type="submit"
value="Login" name="submit">
</td>
</tr>
<tr>
<td>Remember me</td>
<td><input value="1" type="checkbox"
name="checkbox"
<% If Request.Cookies("RememberMeCookie") = "1"
Then
Response.Write "CHECKED"
Else
Response.Write ""
End If %>>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
<%
End Sub
Sub CheckLoginForm
txtUsername=Request.Form("txtUsername")
txtPassword=Request.Form("txtPassword")
If InStr(1,txtUsername,"'",1) > 0 and InStr(1,txtPassword,"'",1)
> 0 then
response.redirect "Login.asp"
Else
If txtUsername = sUsername AND txtPassword = sPassword Then
Session("BlnAdministrator") = True
Response.Redirect "admin.asp"
Else
ShowLoginForm
response.write "<div align='center'>Your login failed.</div>"
End If
End If
End Sub
%>
</body>
</html>
Admin.asp
<%
If Session("BlnAdministrator") <> True Then
Response.Redirect("login.asp")
End If
%>
<html>
<head>
<title>Cookie Login Script</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<div align='center'>Successful login and your username &
password will be remembered if you clicked 'remember me' on login.</div>
</body>
</html>
Membership Software Integrates with PayPal
- Plug and play Membership script.
- Recurring subscriptions or one time payment.
- Up to 3 levels of membership subscription.
- Easy set up and admin with free installation.
- Works with PayPal.
- Receive updates and add-ons for 2 years.
- 1st class support and customization available.
- Can be customized to support more levels.
- Saves you hours and hours of development time and money.
- PURCHASE YOUR COPY TODAY
If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|