MD5 password storage and comparison

Source: Internet
Author: User
I used MD5 encryption to store and compare the MD5 password in mysql during registration. I used md5 () for comparison during login. The value has never been correct, as a result, the comparison fails.


Reply to discussion (solution)

Post the code downstairs

This is the functional module for judgment:
Function pd () {// verify that the password is correct
$ Id = $ _ POST ['id'];
$ Pwd = trim (md5 ($ _ POST ['pwd']);
Echo "$ pwd "."
";
$ SQL = mysql_query ("SELECT * FROM 'XX' WHERE 'id' = '$ ID' AND 'password' =' $ pwd '");
$ SQL _p = mysql_num_rows ($ SQL );
Echo "$ SQL _p ";
If ($ SQL _p = 0 ){
Echo "script" alert ('incorrect password '); window. location. herf = 'index. php'; script ";
}
Else
{Echo "script" alert ('correct password'); script ";}
}

Md5 value in the database;
Root2
E10adc3949ba59abbe56e057f20f88;
The value displayed on the webpage;
E10adc3949ba59abbe56e057f20f883e

$ Pwd = md5 (trim ($ _ POST ['pwd']); // if the problem persists, generate a new md5 value and put it in the database and try again, check if it was inserted incorrectly.

echo md5('root2');mysql_connect();$rs = mysql_query("select md5('root2')");print_r(mysql_fetch_row($rs));
9b70d6dbfb1457d05e4e2c2fbb42d7dbArray(    [0] => 9b70d6dbfb1457d05e4e2c2fbb42d7db)
There is no e10adc3949ba59abbe56e057f20f883e

The e10adc3949ba59abbe56e057f20f883e shown on the webpage
It's not surprising that 123456 won't touch root2 at all.

PS: You can just say that your database is not fully displayed. Basically, it should be because the number of bits set in the password field is unreasonable, resulting in at least two characters less than char (32 ).

1. desc xx: check the table structure. the password field must be 32 characters long.
2.

echo md5('root2');  //9b70d6dbfb1457d05e4e2c2fbb42d7db


E10adc3949ba59abbe56e057f20f883e is the md5 (123456) value.

The landlord can provide the plaintext password and the password recorded in the database.

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.