zoukankan      html  css  js  c++  java
  • 自动生成会员卡号和密码

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

  • 相关阅读:
    CAP 与数据一致性
    C++的构造函数为何不能为虚函数
    构造函数和析构函数中可以调用调用虚函数吗
    HTTP状态码
    C++ 单例模式实现
    【转】十大经典排序算法
    C++ short/int/long/long long 等数据类型大小
    块/文件/对象三种存储的优缺点
    罗振宇《时间的朋友》2019-2020
    Google Hacking
  • 原文地址:https://www.cnblogs.com/yongheng178/p/1913530.html
Copyright © 2011-2022 走看看