Free since 2005 · No login required
AT

Academic Tutorials

Learn at your own pace

site-mobile-top-banner · 320x50

Password Protect your pages using ASP

Added 29 Jul 2008

Have a look at the code for 'login.asp' and then I'll talk you through it. Points to note are that we will be using 2 subroutines, CheckLoginForm and ShowloginForm, and that once the form details are submitted they are sent to the same page to be checked and processed. You could send the form details to another page to be checked and processed but why use an extra page!
The code below is for a simple login that checks for a single username and password. In the following code the username and password are 'mic' and 'pass'.

The 'submit' form button called 'submit' will play an important part in in letting us track whether the form has been submitted. If the form has been submitted then we can use the Request.Form command to collect the values entered in the form textfields and importantly the value sent in the form button 'submit'.

Code for 'login.asp'


Password Protect your pages using ASP

Download the code

Have a look at the code for 'login.asp' and then I'll talk you through it. Points to note are that we will be using 2 subroutines, CheckLoginForm and ShowloginForm, and that once the form details are submitted they are sent to the same page to be checked and processed. You could send the form details to another page to be checked and processed but why use an extra page!
The code below is for a simple login that checks for a single username and password. In the following code the username and password are 'mic' and 'pass'.

The 'submit' form button called 'submit' will play an important part in in letting us track whether the form has been submitted. If the form has been submitted then we can use the Request.Form command to collect the values entered in the form textfields and importantly the value sent in the form button 'submit'.

Code for 'login.asp'

<%
Response.Expires = -1000 'Make sure the browser doesn't cache this page
Response.Buffer = True 'enables our response.redirect to work
%>


Password Protect your ASP pages



<%
If Request.Form("submit") ="Login" Then
CheckLoginForm
Else
ShowLoginForm
End If
%>

<%
Sub CheckLoginForm
'check if the value of the text field 'username' and 'password' are correct
If Request.Form("username") = "mic" AND Request.Form("password") = "pass" Then
Session("BlnLoggedIn") = True
Response.Redirect "memberspage.asp"
Else
'if the values entered are incorrect then display the message below
Response.Write "

You are not logged in.

"
ShowLoginForm
End If
End Sub
%>

<% Sub ShowLoginForm %>







User Name :
Password :




<% End Sub %>