29 lines
808 B
C#
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);
|
|
}
|
|
}
|
|
}
|