MyBookmark/Modules.User.Application/PasswordHasher.cs
THE_KONDRAT 7b16d72329 ui and login
mongo => postgres
2024-11-03 16:08:39 +03:00

32 lines
827 B
C#

using Microsoft.AspNetCore.Identity;
using Modules.User.Domain.Gateways;
namespace Modules.User.Application;
public interface IPasswordHasher
{
public Guid? VerifyPassword(Models.Account? account, string password);
}
public class PasswordHasher : IPasswordHasher, IPasswordGateway
{
private readonly PasswordHasher<string> _hasher;
public PasswordHasher()
{
_hasher = new();
}
public string HashPassword(string password) =>
_hasher.HashPassword("", password);
public Guid? VerifyPassword(Models.Account? account, string password)
{
if (account == null) return null;
if (_hasher.VerifyHashedPassword("", account.HashedPassword, password) != PasswordVerificationResult.Failed)
{
return account.Id;
}
return null;
}
}