许松--永恒学习屋
努力并不一定会成功,但放弃一定会失败!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Text;
using System.Collections;

public partial class MemberNo : System.Web.UI.Page
{
    ArrayList lstNo = GetNo();
    ArrayList lstPwd = GetPwd();

    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = string.Empty;
        SqlConnection con = new SqlConnection("Data Source=192.168.1.178;User Id=sa;Password=myth; Database=test;");
        SqlCommand com = new SqlCommand();
        com = con.CreateCommand();
        con.Open();


        if (!IsPostBack)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(DateTime.Now.ToString() + "<table algin=center border=1 width='100%'>");
            sb.Append("<tr><td>会员卡号</td><td>密码</td><td>MD5值</td></tr>");


            for (int i = 0; i < 10000; i++)
            {
                // sb.Append("<tr><td>" + lstNo[i] + "</td>");
                sb.Append("<tr><td>" + lstNo[i] + "</td>");
                sb.Append("<td>" + lstPwd[i] + "</td>");
                sb.Append("<td>" + Encryption(lstPwd[i].ToString(), "MD5") + "</td>");
                sb.Append("</tr>");

                sql = "Insert into MemberNo(UserId,Password,MD5) values(" + lstNo[i].ToString() + ",'" + lstPwd[i].ToString() + "','" + Encryption(lstPwd[i].ToString(), "MD5") + "') ";
                com.CommandText = sql;
                com.ExecuteNonQuery();
            }
            sb.Append("</table>");
           

            Response.Write(sb.ToString());
        }
    }

    /// <summary>
    /// 生成MD5加密
    /// </summary>
    /// <param name="password"></param>
    /// <param name="format"></param>
    /// <returns></returns>
    public static string Encryption(string password, string format)
    {
        password = password.Trim();
        return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, format).Trim();
    }
    public static ArrayList GetNo()
    {
        ArrayList lst = new ArrayList();
        int No = 88800887;

        while (lst.Count < 10000)
        {
            if (No.ToString().IndexOf("4") < 0 && No.ToString().IndexOf("7") < 0)
            {
                lst.Add(No);
            }
            No++;
        }
        return lst;
    }
    //得到随机密码
    private static ArrayList GetPwd()
    {
        ArrayList lst = new ArrayList();
        Random rd = new Random();
        while (lst.Count < 10000)
        {
            int r = rd.Next(100000, 999999);
            if (!lst.Contains(r))
            {
                lst.Add(r);
            }
        }
        return lst;
    }
    //private static ArrayList GetMemberNo()
    //{
    //    ArrayList lst = new ArrayList();
    //    while (lst.Count < 10000)
    //    {

    //    }
    //    return lst;
    //}
    //得到用户名
    //private static ArrayList GetMemberNo()
    //{
    //    ArrayList lst = new ArrayList();
    //    Random rd = new Random();

    //    while (lst.Count < 10000)
    //    {
    //        int r = rd.Next(10000000, 99999999);
    //        if (!lst.Contains(r))
    //        {
    //            if (r.ToString().IndexOf("4") == -1 || r.ToString().IndexOf("7") == -1)
    //            {
    //                r = rd.Next(10000, 99999);
    //            }
    //            else
    //            {
    //                lst.Add(r);
    //            }
    //        }
    //    }
    //    return lst;
    //}
}

posted on 2010-12-22 11:08  yongheng's blogs  阅读(6877)  评论(0编辑  收藏  举报