healthchecks

This commit is contained in:
2025-08-25 18:52:59 +02:00
parent 5777e351bf
commit 0560a40876
33 changed files with 317 additions and 127 deletions

View File

@@ -5,8 +5,8 @@ public class PasswordGenerator : IPasswordGenerator
public string Generate(int length, bool includeNumbers = true, bool includeMayus = true, bool includeMinus = true, bool includeSpecials = true)
{
const string numbers = "0123456789";
const string mayus = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string minus = "abcdefghijklmnopqrstuvwxyz";
const string mayus = "ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZ";
const string minus = "abcçdefghijklmnñopqrstuvwxyz";
const string specials = "!@#$%^&*()_+[]{}|;:,.<>?";
var characters = minus;
if (includeNumbers) characters += numbers;
@@ -19,6 +19,22 @@ public class PasswordGenerator : IPasswordGenerator
{
password[i] = characters[random.Next(characters.Length)];
}
var positionPool = new List<int>();
for (int i = 0; i < length; i++) positionPool.Add(i);
var forcedRandomNumber = random.Next(0, positionPool.Count);
positionPool.RemoveAt(forcedRandomNumber);
var forcedRandomMayus = random.Next(0, positionPool.Count);
positionPool.RemoveAt(forcedRandomMayus);
var forcedRandomMinus = random.Next(0, positionPool.Count);
positionPool.RemoveAt(forcedRandomMinus);
var forcedRandomSpecial = random.Next(0, positionPool.Count);
positionPool.RemoveAt(forcedRandomSpecial);
password[forcedRandomNumber] = numbers[random.Next(numbers.Length)];
password[forcedRandomMayus] = mayus[random.Next(mayus.Length)];
password[forcedRandomMinus] = minus[random.Next(minus.Length)];
password[forcedRandomSpecial] = specials[random.Next(specials.Length)];
return new string(password);
}
}

View File

@@ -4,12 +4,14 @@ using back.persistance.data;
using back.persistance.data.repositories.Abstracts;
using back.services.engine.Crypto;
using back.services.engine.PasswordGenerator;
using System.Text.Json;
using Transactional.Abstractions.Interfaces;
namespace back.services.engine.SystemUser;
public class SystemUserGenerator(
ITransactionalService<DataContext> transactional,
JsonSerializerOptions jsonSerializerOptions,
IUserRepository userRepository,
IPersonRepository personRepository,
ICryptoService cryptoService,
@@ -21,9 +23,9 @@ public class SystemUserGenerator(
var systemKey = new SystemKey() {
Password = passwordGenerator.Generate(16),
};
var systemKeyJson = System.Text.Json.JsonSerializer.Serialize(systemKey);
var systemKeyJson = JsonSerializer.Serialize(systemKey, options: jsonSerializerOptions);
using Stream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(systemKeyJson));
using Stream stream = new MemoryStream(new System.Text.UTF8Encoding(true).GetBytes(systemKeyJson));
await blobStorageService.Delete("systemkey.lock");
@@ -38,10 +40,16 @@ public class SystemUserGenerator(
if (!await userRepository.Exists(User.SystemUser.Id!))
{
await transactional.DoTransaction(async () => {
await transactional.DoTransaction(async () =>
{
await personRepository.Insert(Person.SystemPerson);
await userRepository.Insert(User.SystemUser);
});
}
else
{
await userRepository.Update(User.SystemUser);
await userRepository.SaveChanges();
}
}
}