dbWriter Simple Log IN / Page protection ASP code
NOTE: Point all hyperlinks to the protected page and the code
at the top of the page will redirect to the login script if NOT logged
in. This script uses a Session variable so you will stay logged in
until you close your browser.
Test LogIN code
Not Logged in!!
<%@ Language=VBScript%>
<% Option Explicit %>
<%
'**********************************
'
' Point all hyperlinks to the protected page the next code line
will redirect if not logged in.
'
' This next line goes at the head of page to be protected.
NOT this login page!!
'
' IF Session("user") <> "LogedON" THEN
response.redirect("login.asp")
'
'**********************************
Response.Buffer=True
on error resume next
DIM Uname
DIM Pass
DIM msgclr
DIM msg
Uname = trim(request.form("User_Name"))
Pass = trim(request.form("Password"))
If Uname = "" and Pass = "" then
msgclr = "#000000"
msg = "Enter your user name and password below!"
Session("user") = ""
ElseIf Uname = "" or Pass = "" then
msgclr = "#FF0000"
msg = "User Name or Password entered is incorrect!"
Session("user") = ""
ElseIf Uname = "test" and Pass = "test" then '<--- Enter User
name and password here
Session("user") = "LogedON"
response.redirect("YourProtectedPage.asp") '<--- Enter redirect here
Else
msgclr = "#FF0000"
msg = "User Name or Password entered is incorrect!"
Session("user") = ""
End If
%>
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<p align="center"> </p>
<form name="form1" method="post" action="">
<div align="center">
<center>
<table width="401" border="1" cellspacing="1" bordercolor="#000000">
<tr>
<td width="393" align="center" colspan="2" nowrap>
<font color="<%=msgclr%>"><%=msg%></font> </td>
</tr>
<tr>
<td width="128" align="left">
<p align="left">User Name:</td>
<td width="264" align="center">
<font color="#FFFFFF">
<input name="User_Name" type="text" id="username"
size="42"></font></td>
</tr>
<tr>
<td width="128" align="left">
<p align="left">Password:</td>
<td width="264" align="center">
<font color="#FFFFFF">
<input name="Password" type="password" id="password"
size="42"></font></td>
</tr>
<tr>
<td width="393" colspan="2" align="center">
<p align="center"><font color="#FFFFFF"><input type="submit"
name="Submit" value="Submit"></font></td>
</tr>
</table>
</center>
</div>
</form>
<p align="center"></p>
</body>
</html> |
|