Minor code clean-up.

This commit is contained in:
2021-01-04 00:25:25 -06:00
parent 45dceef75e
commit 9d70df80f1
4 changed files with 11 additions and 17 deletions
Binary file not shown.
+8 -3
View File
@@ -8,17 +8,22 @@ namespace SecureCore.Authentication
{ {
//Add some pepper to the passwords for good measure: //Add some pepper to the passwords for good measure:
//https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html //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 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 PasswordManager()
{ {
} }
public static (string Hash, string Salt) HashPassword(string password) public static (string Hash, string Salt) HashPassword(string password)
{ {
var salt = new byte[Settings.SaltSize]; var salt = new byte[SaltSize];
ByteGenerator.GetRandomBytes(ref salt); ByteGenerator.GetRandomBytes(ref salt);
@@ -72,7 +77,7 @@ namespace SecureCore.Authentication
private static string GetHash(string password, byte[] salt) 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));
} }
} }
} }
+3 -1
View File
@@ -7,9 +7,11 @@ namespace SecureCore.Authentication
{ {
public class SessionManager public class SessionManager
{ {
private static int SessionKeySize { get; } = 32; //32 bytes
public static string CreateSessionToken() public static string CreateSessionToken()
{ {
var token = new byte[Settings.SessionKeySize]; var token = new byte[SessionKeySize];
ByteGenerator.GetRandomBytes(ref token); ByteGenerator.GetRandomBytes(ref token);
-13
View File
@@ -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
}
}