Basic use of ASP. NET identity 2.0.0 in ASP. NET Core 2.0.0 (iii)

Source: Internet
Author: User

Modify user account and cookie configuration

First, change password strength and user mailbox validation rules:

Open Startup.cs and locate services in public void configureservices (iservicecollection services). Addidentity<applicationuser, applicationrole> () is modified to the following code:

Services. Addidentity<applicationuser, applicationrole> (options =    {                //Configure identity Options//Password Strength configurationOptions. Password.requiredigit =false;//whether a number (0-9) is required.Options. Password.requiredlength =6;//Set the minimum password length to 6Options. Password.requirenonalphanumeric =false;//whether it contains non-alphabetic or numeric characters. Options. Password.requireuppercase =false;//whether to include uppercase letters (A-Z).Options. Password.requirelowercase =false;//whether to include lowercase letters (A-Z).Options. Password.requireduniquechars = 1;//the number of different characters in the password is required. Default is 1//Lock SettingsOptions. Lockout.defaultlockouttimespan = Timespan.fromminutes (5);//Account lockout duration 5 minutesOptions. Lockout.maxfailedaccessattempts =Ten;//10 failed attempts to lock the accountOptions. Lockout.allowedfornewusers =true;//whether to lock new users//User Registration SettingsOptions. User.requireuniqueemail =true;//whether the email address must be uniqueOptions. User.allowedusernamecharacters = "Ab[email protected]+";//User name optional character (letter case + number + ([email protected]+))//Login ConfigurationOptions. Signin.requireconfirmedemail =false;//you need to confirm the email login. The default is False. Options. Signin.requireconfirmedphonenumber =false;//need to confirm the phone number to sign in.                        The default is False.     })    . Addentityframeworkstores<ApplicationDbContext>()    . Adddefaulttokenproviders ();

Second, modify the cookie configuration

Services in public void configureservices (iservicecollection services). Addidentity<applicationuser, add the following code after applicationrole> (): (//the option is very useful)

//cookie Common settings for ApplicationsServices. Configureapplicationcookie (options =            {                //options. Cookie.name = "Yourappcookiename";//the name of the cookied. Default is aspnetcore.cookies.Options. Cookie.httponly =true;//whether to deny cookies from client script access. True by default.Options. Expiretimespan = Timespan.fromminutes ( -);//The cookie remains valid for a period of 60 minutes. //timespan.fromdays ();Options. Loginpath ="/account/login";//automatically redirect when you log in. Options. Logoutpath ="/account/logout";//automatic redirection on logoff. //options. Accessdeniedpath = "/account/accessdenied"; //The user is redirected when there is no authorization check. //options. SlidingExpiration = true;//when True, the new cookie will issue a new expiry time when the current cookie is half past the expiration window.                The default is true. //Requires ' using Microsoft.AspNetCore.Authentication.Cookies; '//options. Returnurlparameter = Cookieauthenticationdefaults.returnurlparameter;//401 status changed to 302 status and redirected to login path. });

Basic use of ASP. NET identity 2.0.0 in ASP. NET Core 2.0.0 (iii)

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.