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 ASPDownload the codeHave 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 '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' <% <% 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 %> <% End Sub %> |