Implemented user settings view

This commit is contained in:
2025-11-23 13:57:02 +01:00
parent 1c311d6e31
commit c554af9479
8 changed files with 286 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using Berufsschule_HAM.Models;
using Berufsschule_HAM.Services;
namespace Berufsschule_HAM.Helpers;
public static partial class UsersHelper
@@ -39,6 +41,14 @@ public static partial class UsersHelper
return cleaned;
}
public static async Task<string> HashPassword(LdapService ldapService, string password)
{
AdminSettingsModel settings = await ldapService.GetAdminSettingsModelAsync();
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
byte[] hashedPassword = settings.hashAlgorithm?.ComputeHash(passwordBytes) ?? throw new Exception("Hash algorithm not instantiated yet");
return $"{{{settings.DefaultHashAlgorithm.ToUpperInvariant()}}}{Convert.ToBase64String(hashedPassword)}";
}
[GeneratedRegex("[^a-z]")]
private static partial Regex AtoZ();
}