0
shyamjith created
Hi,
I am using " _userManager.LoginAsync(usernameOrEmailAddress, password, tenancyName);" Method to login the application, which will accept both username and email address. but my requirement is to authenticate the user only with Username and password not with Email and password, How do I do that?
2 Answer(s)
-
0
override the LoginAsync method and throw an exception if you do not find the user via username. If you find it, call the base LoginAsync method.
I did not test it but it'd be something like this:
[UnitOfWork] public override async Task<AbpLoginResult<Tenant, User>> LoginAsync(string userNameOrEmailAddress, string plainPassword, string tenancyName = null, bool shouldLockout = true) { // this method search for the user by checking just the username field, not the emailaddress fiel. // In this way, if the user passes the email address the method fails throwing an ex. var user = await this.UserManager.FindByNameAsync(userNameOrEmailAddress); // if you are here, the username is OK return await base.LoginAsync(userNameOrEmailAddress, plainPassword, tenancyName, shouldLockout); }
Have an answer to this question?
Log in
and write your answer.