Open Closed

Config Identity #212


0
behiunforgiven created

How can I config Identity with "ApplicationUserManager" and customize "UserValidator" and "PasswordValidator" and ...?


6 Answer(s)
  • 0
    hikalkan created

    In module-zero startup template, you have UserManager class (https://github.com/aspnetboilerplate/mo ... Manager.cs). You can override it's methods to change behaviour.

  • 0
    behiunforgiven created

    You are right , but "UserValidator" is not in override methods,

    How can I override it?

  • 0
    behiunforgiven created

    Can You help me to override "UserValidator" ?

  • 0
    behiunforgiven created

    I wrote PasswordValidator like this

    PasswordValidator = new PasswordValidator() {
                    RequiredLength = 6,
                    RequireNonLetterOrDigit = false,
                    RequireDigit = false,
                    RequireLowercase = false,
                    RequireUppercase = false
                };
    

    but I Can't create UserValidator because of its arguments

    UserValidator = new UserValidator<ApplicationUser>(manager)
                {
                    AllowOnlyAlphanumericUserNames = false,
                    RequireUniqueEmail = false
                };
    

    what is "ApplicationUser" and "manager" in Module Zero?

  • 0
    behiunforgiven created

    I made UserValidator Like this

    UserValidator = new UserValidator<User, long>(this)
                {
                    RequireUniqueEmail = false,
                    AllowOnlyAlphanumericUserNames = false
                };
    

    in the constructor of UserManager, but it still has Error on Emails. I want to Use One Email for All users and Authenticate them only by UserName;

  • 0
    hikalkan created

    Hi,

    User manager itself checks email adress uniqueness (see https://github.com/aspnetboilerplate/mo ... er.cs#L460). So, if you user UserManager's CreateAsync method while creating users, their email adress will be unique.

    But UserManager.LoginAsync method uses email or user name to login. I think this is better and widely used. If it's really needed, you may override or create your own LoginAsync method.