自动生成会员卡号和密码

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() + "

");
            sb.Append("");


            for (int i = 0; i < 10000; i++)
            {
                // sb.Append("

");
                sb.Append("");
                sb.Append("");
                sb.Append("");
                sb.Append("");

                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("

会员卡号密码MD5值
" + lstNo[i] + "
" + lstNo[i] + "" + lstPwd[i] + "" + Encryption(lstPwd[i].ToString(), "MD5") + "
");
           

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

    ///


    /// 生成MD5加密
    ///

    ///
    ///
    ///
    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;
    //}
}

转载于:https://www.cnblogs.com/yongheng178/archive/2010/12/22/1913530.html

你可能感兴趣的:(自动生成会员卡号和密码)