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.