From 9d70df80f10064bc0eedda81cf1928265f4e004b Mon Sep 17 00:00:00 2001 From: Garrritt McCune Date: Mon, 4 Jan 2021 00:25:25 -0600 Subject: [PATCH] Minor code clean-up. --- .vs/SecureCore/v16/.suo | Bin 61952 -> 61952 bytes SecureCore/Authentication/PasswordManager.cs | 11 ++++++++--- SecureCore/Authentication/SessionManager.cs | 4 +++- SecureCore/Authentication/Settings.cs | 13 ------------- 4 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 SecureCore/Authentication/Settings.cs diff --git a/.vs/SecureCore/v16/.suo b/.vs/SecureCore/v16/.suo index 70d44bbfc8b7642ca495d792cb165a817760bca8..c4dc54f5e0effa8a7cfe27dce544e924b74aa863 100644 GIT binary patch delta 572 zcmZp8!rbtLd4j>@3+XHqO(Yl@CpQ`jZ%p7}Viibz5Slc(kS%DkGqWM%?ag1AoEhtt z7#J9Y7#JAT7#JA-{r~@8f`NfSkb!|goPmKsn1O-e|NsC0GZ+{cbfEIm3=9nAP;rnP z2xlVkbr~2K*pT@A3=9lu3=9k$NMa%k3=GZ;3=A3|r62=DL2jIwU^AJAa}T2wh{Ko+ zA~%0v&EXWh!N9<9lYxQZ7Ssv^AqFfcF(FfcGomXB1NY{106`HPT0BPWA4 z0|NudS8(AH34dlz23ZCM23{1^;^)~WAC|XWB+EES!DX|HUOgixBgi$3D5@0w87Ci> zH=JCe+%vhsNsZBPvLch@>x|WS!-QT?#+_P4Td6<0}LcUdMB@YB_trX^OJtD@7d()Ht{CrYw4>tUwCD} IxX5Y;0HVvuCIA2c delta 455 zcmZp8!rbtLd4d5W(?mmQM&`+lhQb>Yc$hdRtg6&Xd~}UbWpgQ8H{&E0i+Vu@1_oIM z1_ogU1_l`h1_m|;1_pix1_p5k1_lKN28RFt|NqZrU|`^2U|{(7|Nnn!1_lO21_lNR z1_lNxsC*t&P9Mq#=}~21V9z+l3_z+lS2 zz+lF}z+le6z~D0Zu7|v)0|NttBLf426Vy78ajpyu3?4|jJsB7n5<%XbnBXI*4wXn@ zU|>jPU|^7hNU%ueFfcG^GcYj7GcYjZGcYg|FfcF_GB7ZdffP)>!Ktx{ErxS)4EK^v z0*9G49~Q7>oFwAB*;&GniPeIEfx&HZrPwJ>1_NkNO_q;ToNU0vKDk7?XOqNXw#A2K z7$+Z=vz?^iGWm#{!R8XZ9>z^d&Ww|t?e{KnV_D?Kv`C9%Q4rH26Q)TS!A;f0FdvIQ~&?~ diff --git a/SecureCore/Authentication/PasswordManager.cs b/SecureCore/Authentication/PasswordManager.cs index 7925ca4..7a22d57 100644 --- a/SecureCore/Authentication/PasswordManager.cs +++ b/SecureCore/Authentication/PasswordManager.cs @@ -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)); } } } diff --git a/SecureCore/Authentication/SessionManager.cs b/SecureCore/Authentication/SessionManager.cs index 5009182..9381245 100644 --- a/SecureCore/Authentication/SessionManager.cs +++ b/SecureCore/Authentication/SessionManager.cs @@ -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); diff --git a/SecureCore/Authentication/Settings.cs b/SecureCore/Authentication/Settings.cs deleted file mode 100644 index bb3ce7b..0000000 --- a/SecureCore/Authentication/Settings.cs +++ /dev/null @@ -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 - } -}