added hashing algorithm + user password hash
This commit is contained in:
@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using Isopoh.Cryptography.Argon2;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace QuickDish.Core;
|
namespace QuickDish.Core;
|
||||||
|
|
||||||
@ -10,7 +6,7 @@ internal class User
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string PasswordHash { get; set; }
|
private string PasswordHash;
|
||||||
|
|
||||||
public User(int id, string username, string passwordHash)
|
public User(int id, string username, string passwordHash)
|
||||||
{
|
{
|
||||||
@ -28,4 +24,16 @@ internal class User
|
|||||||
PasswordHash = passwordHash;
|
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