Authenticating user identities in ASP applications (3)

Source: Internet
Author: User
Third, user authentication

As a simple gauge, this article only discusses user authentication on the server side. The login page is called by the
The Signuseron function in Aspsecurity.inc verifies the identity of the user. Signuseron Check the database
Is there a record that matches the user-entered name and password:
function Signuseron (Asignon, Apassword)
Dim dict
' User-entered name
Asignon = LCase (Trim (Asignon))
' Password entered by user
Apassword = LCase (Trim (apassword))
' Extract user record into Dictionary object
Set dict = GetUser (Asignon)
' Dict object contains legitimate user information
If IsUser (dict) Then
If not dict ("Password") = Apassword Then
Signuseron = False
Session ("MSG") = "bad password."
Exit function
End If

' Update last access time
Call Updatelaston (Asignon)

' Identify user records with SessionID (or ID when not supported cookies)
If not session ("Supportscookies") Then
Session ("ID") = GetID ()
Dict. Add "SessionID", Session ("ID")
Else
Dict. Add "SessionID", Session.SessionID
End If

' Record last activity time
Dict.add "LastActivity", Now ()
' Record current user information in session
Set session ("User") = Dict
' Add the current user to the list of users who are accessing
Call Addusertoapplication (Dict)
Signuseron = True
Else
Session ("MSG") = "User name error"
Signuseron = False
End If
End Function



If the user enters a name and password that matches the records in the database, the Signuseron function returns
True. At this point, the user is authorized, the session ("user") variable contains a Dictionary object, where
The field name and value that contains the database record for the user. In addition, the Dictionary object is also added to the
Application ("user") array for easy access to the user who is currently accessing the secure site
Single. Signuseron used many of the subroutines in the Aspsecurity.inc. Because most of the child processes are
Similar, the following only discusses the GetUser. The function first connects to the database and then extracts the corresponding user notes
Record, and finally converts it to the Dictionary object and returns it, as follows:
function GetUser (Asignon)
Dim conn
Dim R
Set conn = OpenConnection ()
Set R = conn. Execute ("select * from Users WHERE users.signon= '" &
Asignon & "'")
If Err.Number < > 0 Then
' Output error message
......
Response.End
End If
If not r.eof then
Set getuser = Recordtodictionary (R)
Else
Set GetUser = Nothing
End If
R.close
Set R = Nothing
Conn.close
Set conn = Nothing
End Function


If the user clicks the registration button on the registration page, after the necessary checks, it can be counted
A new user record has been generated from the library. Registered successful users will automatically enter the Security page, this part of the operation and
The normal logon process is the same.

Both authentication and registration operations store the error message in the session ("MSG") variable. These false letters
The interest can be displayed in the HTML page returned to the user:
<%
If session ("MSG") < > "" Then
' Display error message
......
Session ("MSG") = ""
End If
%>


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.