Authenticate is jó a passwordhas-sel
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user