ASPNL logo (1 kb)
Thursday, November 20, 2008

powered by


Microsoft ASP.NET Connections
Member of ASP Guild
<< previous | index | next >>
Simple login script

Simple login script

By Roland Mensenkamp
15 June 2001

There's always a situation where you want to protect a page (or more). Here's a simple script to solve a situation like that.
We use a 'Session variable' (so your cookies have to be on).

index.asp
<%
'case 1, the session is true
If Session("pass") Then
   Response.Redirect "page1.asp"
Else
   'Check here if there's a post of a password
   If Request.Form("pass") <> "" Then
      'now check if the post contains the right password
      If Request.Form("pass") = "yourpassword" Then
         Session("pass") = True
         Response.Redirect "page1.asp"
      Else
         'If this isn't the case, you'll be send back
         Response.Redirect "index.asp"
      End If
   End If
'Now follows the HTML form
%>
<html>
<body>

<form method="POST" action="index.asp">
   <div align="center"><center><p><input type="password" name="pass" size="10"><br>
   <input type="submit" value="Login"></p>
   </center></div>
</form>

</body>
</html>
<%End If%>

page1.asp
<%
If Not Session("pass") Then Response.Redirect "index.asp"
%>

These are the few lines of code you need on top of the page. That's all.

<< previous | ^ to top | index | next >>
copyright 2000-2002 ASPNL