protected override void Seed(IdentityDbContext context) { MyUserManager userManager = new MyUserManager(new UserStore <MyUser>(context)); MyRoleManager roleManager = new MyRoleManager(new RoleStore <MyRole>(context)); var role1 = new MyRole { Name = "admin" }; var role2 = new MyRole { Name = "user" }; var admin = new MyUser { Email = "*****@*****.**", UserName = "******", Year = 1990 }; string password = "******"; if (userManager.Create(admin, password).Succeeded) { userManager.AddToRole(admin.Id, role1.Name); userManager.AddToRole(admin.Id, role2.Name); } var user = new MyUser { Email = "*****@*****.**", UserName = "******", Year = 1980 }; password = "******"; if (userManager.Create(user, password).Succeeded) { userManager.AddToRole(user.Id, role2.Name); } user = new MyUser { Email = "*****@*****.**", UserName = "******", Year = 1950 }; password = "******"; if (userManager.Create(user, password).Succeeded) { userManager.AddToRole(user.Id, role2.Name); } base.Seed(context); }
public static MyUserManager Create(IdentityFactoryOptions <MyUserManager> options, IOwinContext context) { MyIdentityDbContext db = context.Get <MyIdentityDbContext>(); MyUserManager myUserManager = new MyUserManager(new UserStore <MyUser>(db)); // Валидация пароля myUserManager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, }; // Влидация имя пользователя myUserManager.UserValidator = new CustomUserValidator(myUserManager); /* * myUserManager.PasswordValidator = new CustomPasswordValidator(5); */ return(myUserManager); }
public CustomUserValidator(MyUserManager mgr) : base(mgr) { AllowOnlyAlphanumericUserNames = false; RequireUniqueEmail = true; }