Add admin access and landing dashboard

This commit is contained in:
2026-05-21 13:43:47 +02:00
parent 6b3dc2de60
commit 9471c5c310
19 changed files with 1442 additions and 456 deletions
@@ -0,0 +1,40 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace TrafagSalesExporter.Services;
internal static class AccessPasswordSettingsWriter
{
private static readonly object FileLock = new();
public static string HashPassword(string password)
=> Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(password)));
public static void SavePasswordHash(string contentRootPath, string sectionName, string passwordHash)
{
var path = Path.Combine(contentRootPath, "appsettings.json");
lock (FileLock)
{
var json = File.Exists(path)
? File.ReadAllText(path, Encoding.UTF8)
: "{}";
var root = JsonNode.Parse(json)?.AsObject() ?? new JsonObject();
var section = root[sectionName] as JsonObject;
if (section is null)
{
section = new JsonObject();
root[sectionName] = section;
}
section["PasswordHash"] = passwordHash;
section["Password"] = string.Empty;
var options = new JsonSerializerOptions { WriteIndented = true };
File.WriteAllText(path, root.ToJsonString(options), new UTF8Encoding(false));
}
}
}