Added basic auth checking code. First bit of code to protect an API call in the Employee controller.

This commit is contained in:
2021-01-03 18:44:08 -06:00
parent 26ea8e8cbc
commit ddb42da7bb
15 changed files with 670 additions and 15 deletions
+10
View File
@@ -1,6 +1,8 @@
using System;
using Microsoft.AspNetCore.Http;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using SecureCore.Services;
namespace SecureCore
{
@@ -37,6 +39,13 @@ namespace SecureCore
return passwordHash == GetPasswordHash(password, saltBytes);
}
public static bool IsAllowed(HttpContext context)
{
if (!context.Request.Cookies.ContainsKey("Session")) return false;
return UserDataService.IsSessionTokenValid(context.Request.Cookies["Session"]);
}
private static string GetPasswordHash(string password, byte[] salt)
{
return Convert.ToBase64String(KeyDerivation.Pbkdf2(password, salt, KeyType, Iterations, KeySize));
@@ -53,5 +62,6 @@ namespace SecureCore
{
public string UserName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
}
}