From 3e8c4b4049a688946602053b83d03c42d24481bb Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Wed, 23 Apr 2025 00:12:43 +0200 Subject: [PATCH] added hashing algorithm + user password hash --- src/QuickDish.Core/QuickDish.Core.csproj | 4 ++++ src/QuickDish.Core/User.cs | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) 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 @@ enable + + + + 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); + } }