chore(codebase): full cleanup pass
This commit is contained in:
@@ -21,38 +21,54 @@ public static class PasswordGenerator
|
||||
bool requireSpecialCharacter = true)
|
||||
{
|
||||
// Create pools based on the requirements
|
||||
var characterPool = new StringBuilder();
|
||||
StringBuilder characterPool = new();
|
||||
|
||||
if (requireNumber)
|
||||
{
|
||||
characterPool.Append(LowerLetters);
|
||||
|
||||
}
|
||||
|
||||
if (requireCapital)
|
||||
{
|
||||
characterPool.Append(UpperLetters);
|
||||
}
|
||||
|
||||
if (requireNumber)
|
||||
{
|
||||
characterPool.Append(Numbers);
|
||||
}
|
||||
|
||||
if (requireSpecialCharacter)
|
||||
{
|
||||
characterPool.Append(SpecialCharacters);
|
||||
}
|
||||
|
||||
// Ensure that the length is within the specified bounds
|
||||
var password = new char[length];
|
||||
char[] password = new char[length];
|
||||
|
||||
// Ensure at least one character from each required category is included
|
||||
int index = 0;
|
||||
|
||||
|
||||
if (requireLowercase)
|
||||
{
|
||||
password[index++] = LowerLetters[Random.Next(LowerLetters.Length)];
|
||||
|
||||
}
|
||||
|
||||
if (requireCapital)
|
||||
{
|
||||
password[index++] = UpperLetters[Random.Next(UpperLetters.Length)];
|
||||
|
||||
}
|
||||
|
||||
if (requireNumber)
|
||||
{
|
||||
password[index++] = Numbers[Random.Next(Numbers.Length)];
|
||||
|
||||
}
|
||||
|
||||
if (requireSpecialCharacter)
|
||||
{
|
||||
password[index++] = SpecialCharacters[Random.Next(SpecialCharacters.Length)];
|
||||
|
||||
}
|
||||
|
||||
// Fill the rest with the password
|
||||
for (int i = index; i < length; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user