This article mainly introduces the PHP user password encryption algorithm, the detailed analysis of the principle of discuz encryption algorithm, and combined with the example of the implementation of the. NET algorithm summarizes the PHP user encryption process and implementation method, the need for friends can refer to the next
Today, take discuz two times to develop in the code to verify the Discuz user name password, the result accidentally fell into the pit, because Discuz forum has two tables to store user data, a discuz in the database Ultrax inside Pre_common_ Member inside, the other is stored in the Ucenter database Ucenter uc_members table. It took a lot of effort to study the Pre_common_member data in the Ultrax Library, to study how its passwords were generated, and to search for a salt that was randomly generated on the web.
How can this randomly generated salt be verified at login time? Then online said in fact Discuz no use that password, their own test, if so, even if the user password pre_common_member inside to get rid of, so can normally log in, it seems that this password is useless, harm me around a big circle.
Okay, get to the point, Discuz's password encryption algorithm is actually two times MD5 encryption, first with plaintext encryption, then randomly generate a salt, and then add the first cipher behind a salt as plaintext and then once again MD5 encryption. The salt is saved in the Uc_members table and can be obtained by user name.
Like this:
MD5 (MD5 (Clear text) +salt)
The following is the implementation code for. NET:
String getdiscuzpwstring (String sourcestr, string salt) { return Getmd5hash (string. Concat (Getmd5hash (SOURCESTR), salt));} String Getmd5hash (String input) { MD5 md5hasher = MD5. Create (); byte[] data = Md5hasher.computehash (Encoding.Default.GetBytes (input)); StringBuilder Sbuilder = new StringBuilder (); for (int i = 0; i < data. Length; i++) { sbuilder.append (Data[i]. ToString ("X2")); } return sbuilder.tostring ();}
Summarize the password to determine the way:
① to install UC
② Open the database Find uc_members This table, look for the last field "salt", copy the value inside
③ Pseudo Code:
$s =MD5 (MD5 ("password"). " The value of the Salt field "); Echo $s;
④ Using if judgment
⑤ say it again! That's a random 6-digit number!
Summary: The above is the entire content of this article, I hope to be able to help you learn.