生成随机密码
导入下面的命名空间
using System.Security.Cryptography;
==============代码=====================
protected string RndPwd()
{
int[] arr = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9,6,6,8,8,9,9,1 };
var r = new RNGCryptoServiceProvider();
var bytes = new byte[arr.Length * 2];
r.GetBytes(bytes);
for (int i = 0; i < bytes.Length; i+=2)
{
int tmp = 0;
int index1 = bytes[i] % arr.Length;
int index2 = bytes[i+1] % arr.Length;
tmp=arr[index1];
arr[index1] = arr[index2];
arr[index2] = tmp;
}
return arr.Aggregate("",(total,ent ) => total += string.Format("{0}", ent)).Substring(0,6);
}