base logic #5
@ -6,7 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="BCrypt.Net.BCrypt" Static="True"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -102,19 +102,21 @@ namespace BusinessLogic.BusinessLogic
|
||||
return UserConverter.ToView(user);
|
||||
}
|
||||
|
||||
public UserViewModel Login(UserBindingModel model)
|
||||
public UserViewModel Login(string email, string password)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(model);
|
||||
|
||||
var user = _userStorage.GetElement(new() { Email = model.Email });
|
||||
if (email is null)
|
||||
{
|
||||
throw new AccountException("Email is null");
|
||||
}
|
||||
var user = _userStorage.GetElement(new() { Email = email });
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
throw new ElementNotFoundException();
|
||||
}
|
||||
// Проверяем пароль
|
||||
_validatePassword(model.Password);
|
||||
if (PasswordHasher.Verify(model.Password, user.PasswordHash))
|
||||
_validatePassword(password);
|
||||
if (!PasswordHasher.Verify(password, user.PasswordHash))
|
||||
{
|
||||
throw new AccountException("The passwords don't match.");
|
||||
}
|
||||
|
@ -16,11 +16,7 @@ namespace BusinessLogic.Tools
|
||||
/// <returns>Хеш пароля</returns>
|
||||
public static string Hash(string password)
|
||||
{
|
||||
using (SHA256 sha256 = SHA256.Create())
|
||||
{
|
||||
byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
return BCrypt.Net.BCrypt.HashPassword(password);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -31,8 +27,7 @@ namespace BusinessLogic.Tools
|
||||
/// <returns></returns>
|
||||
public static bool Verify(string password, string passHash)
|
||||
{
|
||||
var hash = Hash(password);
|
||||
return hash == passHash;
|
||||
return BCrypt.Net.BCrypt.Verify(password, passHash);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user