Updated the Login code so it responds with a set-cookie header for the session token. Still looking into if this is the right thing to do however.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -12,13 +12,13 @@ namespace SecureCore
|
|||||||
private static int SaltSize { get; } = 128 / 8; //128 bit salt
|
private static int SaltSize { get; } = 128 / 8; //128 bit salt
|
||||||
private static int SessionKeySize { get; } = 32; //32 bytes
|
private static int SessionKeySize { get; } = 32; //32 bytes
|
||||||
|
|
||||||
public static string CreateSessionId()
|
public static string CreateSessionToken()
|
||||||
{
|
{
|
||||||
var sessionId = new byte[SessionKeySize];
|
var token = new byte[SessionKeySize];
|
||||||
|
|
||||||
GetRandomBytes(ref sessionId);
|
GetRandomBytes(ref token);
|
||||||
|
|
||||||
return Convert.ToBase64String(sessionId);
|
return Convert.ToBase64String(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (string Hash, string Salt) HashPassword(string password)
|
public static (string Hash, string Salt) HashPassword(string password)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Web;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -15,8 +17,19 @@ namespace SecureCore.Controllers
|
|||||||
public IActionResult Login(LoginInfo info)
|
public IActionResult Login(LoginInfo info)
|
||||||
{
|
{
|
||||||
var (hash, salt) = Authentication.HashPassword(info.Password);
|
var (hash, salt) = Authentication.HashPassword(info.Password);
|
||||||
|
var options = new CookieOptions
|
||||||
|
{
|
||||||
|
Domain = "copyrightcrusader.org",
|
||||||
|
Expires = DateTime.Now.AddDays(7),
|
||||||
|
HttpOnly = true,
|
||||||
|
Secure = true,
|
||||||
|
Path = "/",
|
||||||
|
SameSite = SameSiteMode.Strict
|
||||||
|
};
|
||||||
|
|
||||||
return Ok($"Session Key: {Authentication.CreateSessionId()}{Environment.NewLine}Password Hash: {hash}{Environment.NewLine}Salt: {salt}{Environment.NewLine}");
|
HttpContext.Response.Cookies.Append("Session", Authentication.CreateSessionToken(), options);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,6 @@ namespace SecureCore.Controllers
|
|||||||
{
|
{
|
||||||
return Ok(DataService.GetById(id));
|
return Ok(DataService.GetById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
//[HttpPost("login")]
|
|
||||||
//[AcceptVerbs("POST")]
|
|
||||||
//public IActionResult Login(LoginInfo info)
|
|
||||||
//{
|
|
||||||
// var (Hash, Salt) = Auth.HashPassword(info.Password);
|
|
||||||
|
|
||||||
// return Ok($"Session Key: {Auth.CreateSessionId()}{Environment.NewLine}Password Hash: {Hash}{Environment.NewLine}Salt: {Salt}{Environment.NewLine}");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AuthenticatedUser
|
public class AuthenticatedUser
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SecureCore.Controllers
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class WeatherForecastController : ControllerBase
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
public IEnumerable<WeatherForecast> Get()
|
|
||||||
{
|
|
||||||
var rng = new Random();
|
|
||||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(index),
|
|
||||||
TemperatureC = rng.Next(-20, 55),
|
|
||||||
Summary = Summaries[rng.Next(Summaries.Length)]
|
|
||||||
})
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SecureCore.Models
|
||||||
|
{
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
//public static string
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace SecureCore
|
|
||||||
{
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string Summary { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"additionalProbingPaths": [
|
|
||||||
"C:\\Users\\admin\\.dotnet\\store\\|arch|\\|tfm|",
|
|
||||||
"C:\\Users\\admin\\.nuget\\packages"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"tfm": "netcoreapp3.1",
|
|
||||||
"framework": {
|
|
||||||
"name": "Microsoft.AspNetCore.App",
|
|
||||||
"version": "3.1.0"
|
|
||||||
},
|
|
||||||
"configProperties": {
|
|
||||||
"System.GC.Server": true,
|
|
||||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"additionalProbingPaths": [
|
|
||||||
"C:\\Users\\admin\\.dotnet\\store\\|arch|\\|tfm|",
|
|
||||||
"C:\\Users\\admin\\.nuget\\packages"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"tfm": "netcoreapp3.1",
|
|
||||||
"framework": {
|
|
||||||
"name": "Microsoft.AspNetCore.App",
|
|
||||||
"version": "3.1.0"
|
|
||||||
},
|
|
||||||
"configProperties": {
|
|
||||||
"System.GC.Server": true,
|
|
||||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
||||||
@@ -1 +1 @@
|
|||||||
fe49541232d842c53eb06770dc71b931991ff712
|
1385de9af3cf01bec97de500355f0e8c6e3204e1
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user