Minor code clean-up.
This commit is contained in:
Binary file not shown.
@@ -8,17 +8,22 @@ namespace SecureCore.Authentication
|
||||
{
|
||||
//Add some pepper to the passwords for good measure:
|
||||
//https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
|
||||
public static string Pepper { get; } = "rVk/OwQUw01qy76Q+5WimPk+NdqUMMghftMXyJzzckOj/+eFn056PDYzBD61E/ZNjRdgiMK6RhcHEcdfpJdbcw==";
|
||||
private static string Pepper { get; } = "rVk/OwQUw01qy76Q+5WimPk+NdqUMMghftMXyJzzckOj/+eFn056PDYzBD61E/ZNjRdgiMK6RhcHEcdfpJdbcw==";
|
||||
|
||||
private static string ConnectionString = @"Server=DESKTOP-OEDDVKC\SQLEXPRESS;Database=main;Integrated Security=true;";
|
||||
|
||||
private static int Iterations { get; } = 100000;
|
||||
private static KeyDerivationPrf KeyType { get; } = KeyDerivationPrf.HMACSHA512;
|
||||
private static int KeySize { get; } = 512 / 8;
|
||||
private static int SaltSize { get; } = 128 / 8; //128 bit salt
|
||||
|
||||
public PasswordManager()
|
||||
{
|
||||
}
|
||||
|
||||
public static (string Hash, string Salt) HashPassword(string password)
|
||||
{
|
||||
var salt = new byte[Settings.SaltSize];
|
||||
var salt = new byte[SaltSize];
|
||||
|
||||
ByteGenerator.GetRandomBytes(ref salt);
|
||||
|
||||
@@ -72,7 +77,7 @@ namespace SecureCore.Authentication
|
||||
|
||||
private static string GetHash(string password, byte[] salt)
|
||||
{
|
||||
return Convert.ToBase64String(KeyDerivation.Pbkdf2($"{password}{Pepper}", salt, Settings.KeyType, Settings.Iterations, Settings.KeySize));
|
||||
return Convert.ToBase64String(KeyDerivation.Pbkdf2($"{password}{Pepper}", salt, KeyType, Iterations, KeySize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ namespace SecureCore.Authentication
|
||||
{
|
||||
public class SessionManager
|
||||
{
|
||||
private static int SessionKeySize { get; } = 32; //32 bytes
|
||||
|
||||
public static string CreateSessionToken()
|
||||
{
|
||||
var token = new byte[Settings.SessionKeySize];
|
||||
var token = new byte[SessionKeySize];
|
||||
|
||||
ByteGenerator.GetRandomBytes(ref token);
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
||||
|
||||
namespace SecureCore.Authentication
|
||||
{
|
||||
public static class Settings
|
||||
{
|
||||
public static int Iterations { get; } = 100000;
|
||||
public static KeyDerivationPrf KeyType { get; } = KeyDerivationPrf.HMACSHA512;
|
||||
public static int KeySize { get; } = 512 / 8;
|
||||
public static int SaltSize { get; } = 128 / 8; //128 bit salt
|
||||
public static int SessionKeySize { get; } = 32; //32 bytes
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user