ایجاد رمزهای تصادفی توسط فضای نام System.Security.Cryptography
کد:
public static string CreateRandomEncryptedPassword(int PasswordLen)
{
String allowedChars =
"abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXY Z0123456789";
Byte[] randomBytes = new Byte[PasswordLen];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(randomBytes);
char[] chars = new char[PasswordLen];
int allowedCharCount = allowedChars.Length;
for (int i = 0; i < PasswordLen; i++)
{
chars[i] = allowedChars[(int)randomBytes[i] % allowedCharCount];
}
return new string(chars);
}