Cześć,
masz takiego Nugetta : BCrypt.Net-Next
jak rejestrujesz nowego użytkownika :
using BC = BCrypt.Net.BCrypt;
public async Task RegisterAsync(RegisterRequest request)
{
var newUser = new User
{
UserName = request.UserName,
Password = BC.HashPassword(request.Password)
};
await userServices.CreateAsync(newUser);
}
i ten nuget haszuje ci hasło, tak ze w bazie danych jest zaszyfrowane.
Później przy logowaniu sprawdzasz czy haslo jest poprawne tak:
using BC = BCrypt.Net.BCrypt;
public async Task<LoginResult> AuthenticateAsync(LoginRequest request)
{
var CurrentUser = await userServices.GetUserByEmailAsync(request.Email);
if (CurrentUser == null)
{
throw new Exception($"User with {request.Email} not found.");
}
if (!BC.Verify(request.Password, CurrentUser.Password))
{
throw new Exception($"Credentials for '{request.Email} aren't valid'.");
}
return (new LoginResult
{
UserId = CurrentUser.Id
});
}