Encrypt your site with ASP

Source: Internet
Author: User
Encryption | The site is learning to build a Web site for readers who may be worrying about the security of the site; maybe you're building a non-publicity website, and only system users can access your site. If you are compiling an ASP page, you can easily achieve this by using this article.

First, you need to make a login page, add a form to the HTML, and set it as a spontaneous delivery page.

〈form Name=″login″action=″default. asp″method=″post″target=″-top″〉

Action is followed by the URL on this page so that even if the user logs in incorrectly, you will be prompted on this page without having to return to the previous page. Add in Form

〈input name=″uid″size=″10″maxlength=″10″style=″height:21px; width:101px″〉

〈input name=″pwd″type=″password″size=″10″maxlength=″10″〉


After you complete the HTML, add the program code to the top of the page as follows:

〈%′send customer direct to main page if already logged in

If not IsEmpty (sessions (″cust-id″)) and Len (Session (″cust-id″)) 〉0 then Response.Redirect (″NAVIGATION/DASHBRD. Asp″)

To add your real homepage URL here

End If

′set Flags

Blogin = False

Berror = False

′check Blank Entries

If IsEmpty (Request ″uid″) or Len (request ″uid″) = 0 or IsEmpty (Request (″pwd″)) or Len (Request (″pwd″)) = 0 Then

′need to log in

Blogin = True

Else

′check user credentials against DB

... to verify that the user in your database saved password table

Add the connection database code here

The SQL is as follows ″select * from customer where cust-id=′″& request (″uid″) &″′and′cust-pwd=′″& request (″pwd″) &″′″

The ″uid″ and request (″pwd″) is the text of the user name and password in the form in HTML on this page

Gbfound = False

If not rscust.bof and not rscust.eof then

Gbfound = True

End If

If Gbfound Then

′record useful Customer info in session variables

Session (″cust-id″) = Rscust.fields (″cust-id″)

This is the user name in the database

Session (″cust-pwd″) = Rscust.fields (″cust-pwd″) This is the user password in the database

Session (″power″) = Rscust.fields (″power″) This is the user right in the database [optional]

′update Last login time [optional]

′rscust.activeconnection.execute (″update customer set Cust-login =′″& now &″′where cust_id session (=″&) & ″ ″)

Response.Redirect (″NAVIGATION/DASHBRD. Asp″ Real Homepage URL

Else

′uid and password not found

Berror = True Blogin = True

End If

Rscust.close

′close recordset

Mycn-login.close

Set mycn-login=nothing

′get all policy numbers held by customer

End If

%〉

Finally, all you have to do is add the following code at the beginning of each of your pages:

〈% if IsEmpty (session (″cust-id″)) or Len (Trim (″cust-id″) = 0 Then%〉

〈script language=″javascript″runat=client〉

〈!——

Top.location.href =″. /default. Asp″

——〉

〈script〉

〈% Response.End

End If%〉


where the session (″cust-id″) is the registered username.

Top.location.href =″. /default. Asp″ will automatically navigate to your login interface.

After this process, congratulations, your Web site has a secure login function. Even if someone knows the address of your site, you won't be able to access other pages without legitimate logins. And, after your page times out, you need to log in again, so that even if the operator leaves temporarily, you don't have to worry about the malicious actions of the illegal person.



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.