Convert existing system user passwords to. Text encryption passwords

Source: Internet
Author: User

Because the leader asked to build a blog, he started the use of. Text.

There was already a system with all the user's personal information in it, and the password was not encrypted. I heard from the beginning. text is encrypted with MD5, so I want to import users in the Forum. text in the User table blog_config, but after being imported, we found that users in the original online forum cannot log on. text system. Search for information on Google and find that the original mobile network system uses 16-bit MD5 encryption, while the. Text system uses 32-bit MD5 encryption. Dizzy, no way, only want to convert the unencrypted password into a password that meets the. Text encryption requirements, so I made a small encryption PasswordProgram. Main ProgramCodeAs follows:

Using system. Security. cryptography;

Using system. Web. Security;

// (Remember the using namespaces)

Public static string encrypt (string password) // password encryption program, which is also provided in. Text

{

// Force the string to lower case

//

Password = password. tolower ();

Byte [] clearbytes = new unicodeencoding (). getbytes (password );

Byte [] hashedbytes = (hashalgorithm) cryptoconfig. createfromname ("MD5"). computehash (clearbytes );

Return bitconverter. tostring (hashedbytes );

}

Private void button#click (Object sender, system. eventargs e) // update the password

{



Oledbconnection myconn = new oledbconnection (strconn );

String strsql1 = "select * From tablename"; // your own user and password table

Oledbdataadapter da = new oledbdataadapter (strsql1, myconn );

Oledbcommandbuilder cmdbd = new oledbcommandbuilder (DA );

Myconn. open ();

Datatable TB = new datatable ();

Da. Fill (TB );

Myconn. Close ();

Foreach (datarow myrow in TB. Rows)

{

// Myrow. beginedit ();

Myrow ["password"] = encrypt (myrow ["password"]. tostring ());

// Response. Write (myrow ["password"]. tostring ());

}

// TB. getchanges ();



Myconn. open ();



Da. Update (TB );

// Da. Fill (TB );

Myconn. Close ();



Button1.enabled = false;

}

Remember to create a primary key for the user table. Otherwise, an error occurs. If an error occurs, search for the error information on Baidu to find a lot of solutions.Article.

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.