I am testing to hash using sha1 and i have inserted a row :
insert into tbl_user (username, password, email) values ('maysam', sha1('21lf892'), '[email protected]');
and when i want to select a row like using :
select * from tbl_user where password = sha1('21lf892');
and result is :
Empty set (0.00 sec)
but if i try to select using like username :
select * from tbl_user where username = 'maysam';
+----+----------+--------------------------------+-----------------------+
| id | username | password | email |
+----+----------+--------------------------------+-----------------------+
| 2 | maysam | dd989b1d1d67c6e706852024ccb6a1 | [email protected] |
+----+----------+--------------------------------+-----------------------+
what is the problem? why it can't select ?( i have tested hashing and selecting using md5 and sha2....
A sha1 hash is 160bits, i.e. 40 characters when formatted in this way.
Your table appears to have the length of the password column set to something smaller than this, so the data is truncated on insert and is no longer equal to sha1('21f892')
.
As an aside, unsalted SHA1 hashes is a very weak way to store passwords. Prefer something like bcrypt or scrypt.