45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Modules.Account.Domain.Gateways;
|
|
|
|
namespace Modules.Account.Domain.Entities;
|
|
|
|
public class Account
|
|
{
|
|
public Guid Id { get; set; }
|
|
public Email Email { get; private set; }
|
|
public string HashedPassword { get; private set; }
|
|
|
|
public Account(Guid id, string email, string hashedPassword)
|
|
{
|
|
Id = id;
|
|
Email = new Email(email);
|
|
HashedPassword = hashedPassword;
|
|
}
|
|
|
|
private Account(Email email)
|
|
{
|
|
Email = email;
|
|
HashedPassword = "";
|
|
}
|
|
|
|
public static Account Create(string email, string password, IPasswordHasher passwordHasher)
|
|
{
|
|
var account = new Account(new Email(email));
|
|
var a = passwordHasher.HashPassword(account, password);
|
|
return account;
|
|
}
|
|
|
|
public void SetPassword(string email)
|
|
{
|
|
//var newPasswordHash = passwordHasher.HashPassword(password);
|
|
//if (newPasswordHash != HashedPassword) throw new Exception("Password must not be aqual to previous");
|
|
if (string.IsNullOrWhiteSpace(email)) throw new Exception("Email is empty");
|
|
Email = new Email(email);
|
|
}
|
|
|
|
public void SetPassword(string password, IPasswordHasher passwordHasher)
|
|
{
|
|
var newPasswordHash = passwordHasher.HashPassword(this, password);
|
|
if (newPasswordHash != HashedPassword) throw new Exception("Password must not be aqual to previous");
|
|
HashedPassword = newPasswordHash;
|
|
}
|
|
} |