code example-Ask for Login

Source: Internet
Author: User
The need for a security system is obvious if your pages include sensitive information.
This sample shows you to setup some of your pages to ask for login if the user has not logged in yet.
2enetworx/dev site uses this kind the protection for interactive pages and file downloads.
Let ' s assume that we have a page where the visitors can ask questions. We want to make sure this user has logged in before being to ask a able.
If the user has not logged in yet, we'll ask for a login. After a successful login, we'll redirect the user to the page requested.
We'll have a common file to check for login. You are need to include this file into all of the pages that require login.
Security.asp
<%
Bloggedin = (Len (Session ("UserName")) > 0)
If Brequirelogin Then
' Login required
If not Bloggedin then
' Not logged in, ask for login
Response.Redirect "Login.asp?comebackto=" & _
Request.ServerVariables ("Script_name") & "?" & _
Server.URLEncode (Request.QueryString)
' How do we construct the page to come back
End If
End If
%>
Login.asp
The the page where the user is redirected from thing. The variable sreferer is used to redirect the page of the user has come from.
Sgobackto variable'll used in the <form> tags for persisting this location when we submit the login form.
<%
If Request ("Comebackto") <> "then
Sreferer = Request ("Comebackto")
Sgobackto = "?" & Request.QueryString
End If
If Request ("Cmdlogin") <> "then
' Login Form submitted
sUserName = Request ("txtUserName")
Spassword = Request ("Txtpassword")
' Check for username and password
If sUserName = "Bill" and Spassword = "Gates" Then
Bloginsuccessful = True
End If
Session ("UserName") = sUserName
' After a successful login, let ' s send the user

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.