slqwell

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 1public static string MakePassword(string pwdchars, int pwdlen)
 2        {
 3            string tmpstr = "";
 4            int iRandNum;
 5            Random rnd = new Random();
 6            for(int i=0;i<pwdlen;i++)
 7            {
 8                iRandNum = rnd.Next(pwdchars.Length);
 9                tmpstr += pwdchars[iRandNum];
10            }

11            return tmpstr;
12        }

13

 

其中pwdchars 为密码中出现的字符,pwdlen为密码的长度
  2、后台的代码:

 1private void Page_Load(object sender, System.EventArgs e)
 2        {
 3            if(!IsPostBack)
 4            {
 5                string randomchars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 6
 7                string password = Class1.MakePassword(randomchars, 10);
 8                Response.Write(password);
 9            }

10            // 在此处放置用户代码以初始化页面
11        }

12
13



posted on 2005-09-01 15:44  slqwell  阅读(371)  评论(0)    收藏  举报