Automatically generate membership card numbers and passwords

Source: Internet
Author: User
Tags md5 encryption

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)
{< br> stringbuilder sb = new stringbuilder ();
Sb. append (datetime. now. tostring () + "


"); Sb. append (" ");
membership card number password MD5 value

for (INT I = 0; I <10000; I ++)
{< br> // sb. append (" " + lstno [I] + "");
Sb. append (" " + lstno [I] + "");
Sb. append ("" + lstpwd [I] + "");
Sb. append ("" + encryption (lstpwd [I]. tostring (), "MD5") + "");
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 ("</table> ");

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

/// <Summary>
/// Generate MD5 Encryption
/// </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;
}
// Obtain the Random Password
Private Static arraylist getpwd ()
{
Arraylist lst = new arraylist ();
Random RD = new random ();
While (lst. Count <10000)
{
Int r = RD. Next (100000,999 999 );
If (! Lst. Contains (r ))
{
Lst. Add (R );
}
}
Return lst;
}
// Private Static arraylist getmemberno ()
//{
// Arraylist lst = new arraylist ();
// While (lst. Count <10000)
//{

//}
// Return lst;
//}
// Obtain the user name
// Private Static arraylist getmemberno ()
//{
// Arraylist lst = new arraylist ();
// Random RD = new random ();

// While (lst. Count <10000)
//{
// Int r = RD. Next (10000000,999 99999 );
// If (! Lst. Contains (r ))
//{
// If (R. tostring (). indexof ("4") =-1 | r. tostring (). indexof ("7") =-1)
//{
// R = RD. Next (10000,999 99 );
//}
// Else
//{
// Lst. Add (R );
//}
//}
//}
// Return lst;
//}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.