Base solution for your next web application
Open Closed

How to retrieve all the users with email and password #752


User avatar
0
sampath created

Hi, Can you tell me how to retrieve all the users ? Thanks.

I have tried this.But it's not working.I know problem here is the password.But how can I send the password here ?

using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var users = _userManager.Users.Where(u => u.EmailAddress == usernameOrEmailAddress && u.Password == password).ToList(); 
}

6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You need to hash password. Use PasswordHasher. example: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/e122c1d1c1eb46636fd0e0e77a5188e3c7befb9c/src/Tests/Abp.Zero.SampleApp.Tests/TestDatas/InitialUsersBuilder.cs#L34">https://github.com/aspnetboilerplate/mo ... der.cs#L34</a>

  • User Avatar
    0
    sampath created

    Nope,It is not working.B'cos it creates a new hash password.But I need to retrieve the existing records. I need to check the already stored password and plain password where user enters on the login page. Is that possible ? Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    Then get just by user name or email and check password in the code.

  • User Avatar
    0
    sampath created

    Sorry,I couldn't get what you told.I can retrieve the data according to the email address.But then how can I compare it with the plain password ? Same issue will be occurred again no ? any code snippet please. Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    new PasswordHasher().VerifyHashedPassword(hashedPassword, providedPassword);

  • User Avatar
    0
    sampath created

    Thanks a lot :)

    var result = _userManager.PasswordHasher.VerifyHashedPassword(hashedPassword, providedPassword);
      if (result == PasswordVerificationResult.Success){}