added hashing algorithm + user password hash

This commit is contained in:
2025-04-23 00:12:43 +02:00
parent 8656254ff5
commit 3e8c4b4049
2 changed files with 18 additions and 6 deletions

View File

@ -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>

View File

@ -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);
}
} }