SVN
This commit is contained in:
28
Managers/GeneratorManager.cs
Normal file
28
Managers/GeneratorManager.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user