public static class clsPassGen
{
public static string GetRandomString(int length)
{
const string alphanumericCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
if (length < 0) return "";
if (length > int.MaxValue / 8) length = 100;
var characterArray = alphanumericCharacters.Distinct().ToArray();
var bytes = new byte[length * 8];
new RNGCryptoServiceProvider().GetBytes(bytes);
var result = new char[length];
for (var i = 0; i < length; i++)
{
var value = BitConverter.ToUInt64(bytes, i * 8);
result[i] = characterArray[value % (uint)characterArray.Length];
}
return new string(result);
}
}