John Davidson

php - Empty set is returned when set condition for password

0 comments
Message:


Im quite new in mysql


I have inserted values into my table customer


INSERT INTO customer(f_name, l_name, mobilehp, username, password)
VALUES
('Ahmad', 'Ali', '013-5404997', 'A_Ali', SHA('something'));

Then I inserted a condition,


select customer_id, f_name FROM customer WHERE password=SHA('something');

However the query returned empty set which is weird when it supposed to display customer_id and f_name. So any help would be greatly appreciated. Thanks



My Answer:
The issue you are facing is likely due to the fact that the SHA function in MySQL returns a binary string, which may not match the string representation of the hashed password you are comparing it to.

To resolve this issue, you can convert the hashed password to a hexadecimal string before comparing it in the query. You can do this using the HEX function in MySQL. Here is an example query that should work for you:

sql
SELECT customer_id, f_name
FROM customer
WHERE password = HEX(SHA('something'));


By converting the hashed password to a hexadecimal string before comparing it, you should be able to retrieve the correct customer_id and f_name from the database.

Rate this post

3 of 5 based on 4284 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us