This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SimPas2-Windows/Managers/GeneratorManager.cs
2026-01-21 03:07:35 +09:00

29 lines
808 B
C#

using System.Security.Cryptography;
namespace SimPas2_Windows.Managers
{
public class GeneratorManager
{
public GeneratorManager()
{
}
public string GeneratePassword(bool isSecure, int length)
{
const string charset_risky = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const string charset_secure = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()=~-^\\|_@`[{]};:+*<>,./?";
string charset = isSecure ? charset_secure : charset_risky;
byte[] random = RandomNumberGenerator.GetBytes(length);
char[] res = new char[length];
for (int i = 0; i < length; i++)
{
res[i] = charset[random[i] % charset.Length];
}
return new string(res);
}
}
}