Introduction to membership

Source: Internet
Author: User

Introduction to membership
2.Settings of membership in SQL Server
3.Configure web. config
4.Create user createuserwizard Control
5.Log on to the login Control
6.Display the loginname control of the current user
7.Loginstatus Control for detecting the user's authentication status
8.Displays loginview controls for different types of users.
9.Changepassword Control for Password Change
10.Passwordrecovery Control for password retrieval
11.Summary

1. Introduction to membership

Membership is really interesting, convenient, and useful. This article will be introduced to you.
In ASP. NET applications, the membership class is used to authenticate user creden。 and manage user settings (such as passwords and email addresses ). The membership class can be used independently or together with formsauthentication to create a complete Web application or website user authentication system. The login control encapsulates the membership class to provide a convenient user authentication mechanism.
The membership class provides the following functions:
1) create a new user.
2) store the Membership Information (username, password, email address, and supported data) in Microsoft SQL Server or similar data storage areas.
3) authenticate the users accessing the website. Users can be authenticated programmatically, or a complete authentication system with few or no code is created using the login control.
4) Manage the password. Including creating, changing, retrieving, and resetting passwords. You can choose to configure ASP. Net membership to require a password to prompt questions and their answers to perform identity verification for Password Reset and retrieval requests of users who forget the password.
By default, ASP. NET membership supports all ASP. NET applications. The default membership provider is sqlmembershipprovider and is specified in the computer configuration with the name aspnetsqlprovider. The default instance of sqlmembershipprovider is a local instance connected to Microsoft SQL Server.

2. settings of membership in SQL Server

To use membership, you need to make some settings for the database. Those who have used membership know that there are some inherent tables, views, and stored procedures in the database. Our own tables do not have these things.
Finally, we can use the Wizard to create them, that is, aspnet_regsql.exe, which is generally located at: C: \ WINDOWS \ Microsoft. NET \ framework \ v2.0.50727 (here I am)
It can create options in the database or remove these settings.
Before running this program, I created an empty database in SQL server2005: membershipdemo.
After establishing membershipdemo, run aspnet_regsql.exe and specify membership as membershipdemo.
[Attach] 34768 [/Attach]
After completion, the empty database will have a lot of content, but the specific content is not required for the moment. Continue with the subsequent content.
[Attach] 34769 [/Attach]

3. Configure web. config

Web. config also needs to be modified.
Add an authentication node under the system. Web Node
Since membership is used for member qualification management, of course, login authentication is required, so first add a form authentication.

[Copy to clipboard] [-]

Code:

<Authentication mode = "forms">
<Forms loginurl = "login. aspx" name = ". aspxlogin"/>
</Authentication>

Add a membership node to the system. Web node.

[Copy to clipboard] [-]

Code:

<Membership defaultprovider = "aspnetsqlmembershipprovider" userisonlinetimewindow = "15" hashalgorithmtype = "">
<Providers>
<Clear/>
<Add connectionstringname = "connectionstring" enablepasswordretrieval = "false" enablepasswordreset = "true" Success = "true" applicationname = "/" requiresuniqueemail = "false" passwordformat = "hashed" Success =" 5 "minrequiredpasswordlength =" 7 "minrequirednonalphanumericcharacters =" 1 "passwordattemptwindow =" 10 "passwordstrengthregularexpression =" "name =" aspnetsqlmembershipprovider "type =" system. web. security. sqlmembershipprovider, system. web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "/>
</Providers>
</Membership>

Attribute description:
Defaultprovider: Name of the provider. The default value is aspnetsqlmembershipprovider. If you have multiple providers, it is wise to specify a default value.
Userisonlinetimewindow: Specify the number of minutes that the user is considered online after the date/timestamp of the last activity.
Hashalgorithmtype: The identifier of the algorithm used to hash the password, or is null to use the default hash algorithm.
Connectionstringname: The connection name of the membership database.
Enablepasswordretrieval: Indicates whether the current membership provider is configured to allow users to retrieve their passwords.
Enablepasswordreset: Indicates whether the current membership provider is configured to allow users to reset their passwords.
Requiresquestionandanswer: Indicates whether the default membership provider requires the user to answer the password prompt questions during password reset and retrieval.
Applicationname: Application name.
Requiresuniqueemail: Indicates whether the membership provider is configured to require each user name to have a unique email address.
Passwordformat: Indicates the format of the password stored in the member qualification data storage area. Values include clear, encrypted, and hashed. Clear passwords are stored in plain text, which improves the performance of storing and retrieving passwords, but are less secure. When the security of data sources is threatened, such passwords are easily read. The encrypted password is encrypted during storage and can be decrypted during password comparison or retrieval. This type of password requires additional processing during storage and retrieval, but it is relatively secure and is not easy to obtain when the security of the data source is threatened. When the hashed password is stored in the database, it uses a one-way hash algorithm and a randomly generated salt value for hash processing. When a password is verified, the password is hash calculated using the salt value in the database for verification. The hash password cannot be retrieved.
Maxinvalidpasswordattempts: Number of attempts to prompt questions and answers to the invalid or invalid passwords allowed before the user is locked.
Minrequiredpasswordlength: Minimum length required by the password.
Minrequirednonalphanumericcharacters: The minimum number of special characters that a valid Password must contain.
Passwordattemptwindow: The maximum number of minutes that a question answer attempt can be prompted for an invalid password or password before the user is locked. This is an additional measure to prevent unknown sources from repeatedly trying to guess the password of a Member-qualified user or the password prompts the answer to the question.
Passwordstrengthregularexpression: Calculate the regular expression of the password.

After configuring web. config for membership, configure its role management rolemanager.
Also in system. Web

[Copy to clipboard] [-]

Code:

<Rolemanager enabled = "true" cacherolesincookie = "true">
<Providers>
<Clear/>
<Add connectionstringname = "connectionstring" applicationname = "/" name = "aspnetsqlroleprovider" type = "system. web. security. sqlroleprovider, system. web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a "/>
</Providers>
</Rolemanager>

Attribute description:
Cacherolesincookie: Indicates whether the role of the current user has been cached in a cookie.
When the cacherolesincookie attribute is set to true in the configuration file, the role information of each user is stored in a cookie on the client. When role management checks whether a user belongs to a specific role, it checks the role cookie before calling the role provider to check the role list in the data source. The cookie is dynamically updated on the client to cache recently verified role names.
Web. config is configured almost.

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.