transactions
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using DependencyInjector.Lifetimes;
|
||||
|
||||
namespace back.services.engine.PasswordGenerator;
|
||||
|
||||
public interface IPasswordGenerator : ISingleton
|
||||
{
|
||||
string Generate(int length, bool includeNumbers = true, bool includeMayus = true, bool includeMinus = true, bool includeSpecials = true);
|
||||
}
|
24
back/services/engine/PasswordGenerator/PasswordGenerator.cs
Normal file
24
back/services/engine/PasswordGenerator/PasswordGenerator.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace back.services.engine.PasswordGenerator;
|
||||
|
||||
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 specials = "!@#$%^&*()_+[]{}|;:,.<>?";
|
||||
var characters = minus;
|
||||
if (includeNumbers) characters += numbers;
|
||||
if (includeMayus) characters += mayus;
|
||||
if (includeSpecials) characters += specials;
|
||||
var random = new Random((int)DateTimeOffset.UtcNow.Ticks);
|
||||
var password = new char[length];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
password[i] = characters[random.Next(characters.Length)];
|
||||
}
|
||||
return new string(password);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user