diff --git a/src/WorkFlowCheck.Common/Security/PasswordHasher.cs b/src/WorkFlowCheck.Common/Security/PasswordHasher.cs index 69d524a..834c335 100644 --- a/src/WorkFlowCheck.Common/Security/PasswordHasher.cs +++ b/src/WorkFlowCheck.Common/Security/PasswordHasher.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Data.SqlTypes; using System.Linq; using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -10,14 +12,12 @@ namespace WorkFlowCheck.Common.Security public static class PasswordHasher { // Jelszó hashelése + private const string _saltstring = "xc45DDfrt!!ED210:"; public static string HashPassword(string password) { // Generate a random salt - byte[] salt = new byte[16]; - using (var rng = RandomNumberGenerator.Create()) - { - rng.GetBytes(salt); - } + byte[] salt = Encoding.UTF8.GetBytes(_saltstring); + // Hash the password with the salt using (var rfc2898 = new Rfc2898DeriveBytes(password, salt, 10000, HashAlgorithmName.SHA256)) @@ -37,7 +37,7 @@ namespace WorkFlowCheck.Common.Security byte[] hashBytes = Convert.FromBase64String(storedPasswordHash); // Extract salt (first 16 bytes) and stored hash (next 32 bytes) - byte[] salt = new byte[16]; + byte[] salt = Encoding.UTF8.GetBytes(_saltstring); byte[] storedHash = new byte[32]; Array.Copy(hashBytes, 0, salt, 0, 16); Array.Copy(hashBytes, 16, storedHash, 0, 32); diff --git a/src/WorkFlowCheck.DL/Entities/User.cs b/src/WorkFlowCheck.DL/Entities/User.cs index 0bc318f..850a5b6 100644 --- a/src/WorkFlowCheck.DL/Entities/User.cs +++ b/src/WorkFlowCheck.DL/Entities/User.cs @@ -9,6 +9,6 @@ namespace WorkFlowCheck.DL.Entities public string FirstName { get; set; } = null!; public string LastName { get; set; } = null!; public string UserName { get; set; } = null!; - public string PasswordHash { get; set; } + public string? PasswordHash { get; set; } = null; } } diff --git a/src/WorkFlowCheck.DL/Seed/DBInitializer.cs b/src/WorkFlowCheck.DL/Seed/DBInitializer.cs index 94bff3c..0c286bf 100644 --- a/src/WorkFlowCheck.DL/Seed/DBInitializer.cs +++ b/src/WorkFlowCheck.DL/Seed/DBInitializer.cs @@ -1,8 +1,10 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WorkFlowCheck.Common.Security; namespace WorkFlowCheck.DL.Seed { @@ -10,7 +12,12 @@ namespace WorkFlowCheck.DL.Seed { public static void Seed(AppDbContext dbContext) { - + var user = dbContext.Users.Where(w => w.Email == "info@wfcapi.hu").FirstOrDefault(); + if (user != null && user.PasswordHash == null) + { + user.PasswordHash = PasswordHasher.HashPassword("861354"); + dbContext.SaveChanges(); + } } } } diff --git a/src/WorkFlowCheck.DL/WorkFlowCheck.DL.csproj b/src/WorkFlowCheck.DL/WorkFlowCheck.DL.csproj index 2d72b84..f436ba4 100644 --- a/src/WorkFlowCheck.DL/WorkFlowCheck.DL.csproj +++ b/src/WorkFlowCheck.DL/WorkFlowCheck.DL.csproj @@ -15,4 +15,8 @@ + + + +