added hashing algorithm + user password hash
This commit is contained in:
@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Isopoh.Cryptography.Argon2;
|
||||
|
||||
namespace QuickDish.Core;
|
||||
|
||||
@ -10,7 +6,7 @@ internal class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string PasswordHash { get; set; }
|
||||
private string PasswordHash;
|
||||
|
||||
public User(int id, string username, string passwordHash)
|
||||
{
|
||||
@ -28,4 +24,16 @@ internal class User
|
||||
PasswordHash = passwordHash;
|
||||
}
|
||||
|
||||
public bool VerifyPassword(string password)
|
||||
{
|
||||
return Argon2.Verify(PasswordHash, password);
|
||||
}
|
||||
|
||||
public void SetPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
throw new ArgumentException("Password can't be empty", nameof(password));
|
||||
|
||||
PasswordHash = Argon2.Hash(password);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user