asp core 配置用户密码验证
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using Microsoft.AspNetCore.Builder; 6 using Microsoft.AspNetCore.Identity; 7 using Microsoft.EntityFrameworkCore; 8 using Microsoft.AspNetCore.Hosting; 9 using Microsoft.Extensions.Configuration; 10 using Microsoft.Extensions.DependencyInjection; 11 using Cap.Data; 12 using Cap.Models; 13 using Cap.Services; 14 using Microsoft.AspNetCore.Authentication.Cookies; 15 16 namespace Cap 17 { 18 public class Startup 19 { 20 public Startup(IConfiguration configuration) 21 { 22 Configuration = configuration; 23 } 24 25 public IConfiguration Configuration { get; } 26 27 // This method gets called by the runtime. Use this method to add services to the container. 28 public void ConfigureServices(IServiceCollection services) 29 { 30 services.AddDbContext<ApplicationDbContext>(options => 31 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 32 33 services.AddIdentity<ApplicationUser, IdentityRole>() 34 .AddEntityFrameworkStores<ApplicationDbContext>() 35 .AddDefaultTokenProviders(); 36 37 // Add application services. 38 services.AddTransient<IEmailSender, EmailSender>(); 39 40 services.AddMvc(); 41 services.Configure<IdentityOptions>(options => 42 { 43 options.Password.RequireDigit = false; 44 options.Password.RequireLowercase = false; 45 options.Password.RequireNonAlphanumeric = false; 46 options.Password.RequireUppercase = false; 47 options.Password.RequiredLength = 6; 48 }); 49 } 50 51 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 52 public void Configure(IApplicationBuilder app, IHostingEnvironment env) 53 { 54 if (env.IsDevelopment()) 55 { 56 app.UseDeveloperExceptionPage(); 57 app.UseBrowserLink(); 58 app.UseDatabaseErrorPage(); 59 } 60 else 61 { 62 app.UseExceptionHandler("/Home/Error"); 63 } 64 65 66 app.UseStaticFiles(); 67 68 app.UseAuthentication(); 69 70 app.UseMvc(routes => 71 { 72 routes.MapRoute( 73 name: "default", 74 template: "{controller=Home}/{action=Index}/{id?}"); 75 }); 76 } 77 } 78 }