diff --git a/src/QuickDish.Core/QuickDish.Core.csproj b/src/QuickDish.Core/QuickDish.Core.csproj index 125f4c9..73448f3 100644 --- a/src/QuickDish.Core/QuickDish.Core.csproj +++ b/src/QuickDish.Core/QuickDish.Core.csproj @@ -6,4 +6,8 @@ <Nullable>enable</Nullable> </PropertyGroup> + <ItemGroup> + <PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" /> + </ItemGroup> + </Project> diff --git a/src/QuickDish.Core/User.cs b/src/QuickDish.Core/User.cs index a7417ba..4fb80aa 100644 --- a/src/QuickDish.Core/User.cs +++ b/src/QuickDish.Core/User.cs @@ -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); + } }