Added basic auth checking code. First bit of code to protect an API call in the Employee controller.
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user