Asp.net ID - SetPasswordHashAsync

I am trying to configure authentication to work with a custom provider. So far so good, I created a UserStore :

 public class UserStore : IUserStore<User>, IUserPasswordStore<User> 

(with all methods implemented) and UserManager:

 public UserManager(IUserStore<User> userStore) : base(userStore) { } 

and User is my user object for storing users.

The problem is that in UserStore I have the following:

 public async Task SetPasswordHashAsync(User user, string passwordHash) 

From what I understood, this is called before the user is created, so all I have to do is:

 public Task SetPasswordHashAsync(User user, string passwordHash) { user.PasswordHash = passwordHash; } 

... but this should return the task, and I don't see anything asynchronous here.

  • Why return type is Task for SetPasswordHashAsync and not just void?
  • How do I implement SetPasswordHashAsync ?

I know I can do something like

 public async Task SetPasswordHashAsync(User user, string passwordHash) { user.PasswordHash = passwordHash; await Task.FromResult(0); } 

... but isn't it synchronous? It is strange to see all the other methods decorated with async Task, and use await , and this one, to return Task.FromResult()

Is anyone

+6
source share
1 answer

Tasks should not be asynchronous. You can implement it as follows:

 public Task SetPasswordHashAsync(User user, string passwordHash) { user.PasswordHash = passwordHash; return Task.FromResult(0); } 
+8
source

Source: https://habr.com/ru/post/987079/


All Articles