华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7 KiB

5 months ago
  1. using System.Threading.Tasks;
  2. using Microsoft.AspNet.Identity;
  3. using Microsoft.AspNet.Identity.EntityFramework;
  4. using Microsoft.AspNet.Identity.Owin;
  5. using Microsoft.Owin;
  6. using WebApplication1.Models;
  7. namespace WebApplication1
  8. {
  9. // 配置此应用程序中使用的应用程序用户管理器。UserManager 在 ASP.NET Identity 中定义,并由此应用程序使用。
  10. public class ApplicationUserManager : UserManager<ApplicationUser>
  11. {
  12. public ApplicationUserManager(IUserStore<ApplicationUser> store)
  13. : base(store)
  14. {
  15. }
  16. public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
  17. {
  18. var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
  19. // 配置用户名的验证逻辑
  20. manager.UserValidator = new UserValidator<ApplicationUser>(manager)
  21. {
  22. AllowOnlyAlphanumericUserNames = false,
  23. RequireUniqueEmail = true
  24. };
  25. // 配置密码的验证逻辑
  26. manager.PasswordValidator = new PasswordValidator
  27. {
  28. RequiredLength = 6,
  29. RequireNonLetterOrDigit = true,
  30. RequireDigit = true,
  31. RequireLowercase = true,
  32. RequireUppercase = true,
  33. };
  34. var dataProtectionProvider = options.DataProtectionProvider;
  35. if (dataProtectionProvider != null)
  36. {
  37. manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
  38. }
  39. return manager;
  40. }
  41. }
  42. }