所以我有一个带ASP身份的MVC5项目,我没有直接访问用户数据库,而是提供了Web服务,例如:
bool register (string username, string password, string email) //password is plain text
bool login (string username, string password)
我的问题是我不知道如何实现IUserPasswordStore,因为ASP身份迫使我使用哈希,而我不允许存储哈希密码,因为这个Web服务不仅仅会被我使用。
我的UserStore.cs:
public Task<string> GetPasswordHashAsync(TUser user)
{
//I'm suppose to provide hashed password here, but since I don't have any hashed password stored, I have no idea how to implement this method
string passwordHash = userTable.GetPassword(user.Id);
return Task.FromResult<string>(passwordHash);
}
public Task<bool> HasPasswordAsync(TUser user)
{
var hasPassword = !string.IsNullOrEmpty(userTable.GetPassword(user.Id));
return Task.FromResult<bool>(Boolean.Parse(hasPassword.ToString()));
}
public Task SetPasswordHashAsync(TUser user, string passwordHash)
{
//do nothing since I don't need to hash the password
return Task.FromResult<Object>(null);
}
答案 0 :(得分:1)
您的应用程序没有密码存储,请勿实现此功能。
覆盖SignInManager中的PasswordSignInAsync方法,让它调用您的Web服务。