Select in encrypted value

2

Well, I created a table and entered a value into a field using SHA1 (encrypt), and I do not know how to select the value for that encrypted field. TABLE:

CREATE DATABASE IF NOT EXISTS 'quest';
USE 'quest';
CREATE TABLE IF NOT EXISTS 'users'( 
'username' CHAR(32) DEFAULT NULL,
'password' CHAR(32) DEFAULT NULL,
'email' varchar(100) DEFAULT NULL,
'perm' int(10) NOT NULL DEFAULT 1,
UNIQUE KEY 'username' ('username')
);

INSERT:

INSERT INTO 'users'('username', 'password', 'email', 'perm') VALUES ("admin", SHA1("admin"), "[email protected]", 2);

I tried to do this:

SELECT * FROM 'users' WHERE 'password' = SHA1('admin')

Return:

 MySQL não retornou nenhum registo. (O Query demorou 0.0040 sec)

Does anyone know how to do it? Thank you.

    
asked by anonymous 12.09.2014 / 15:08

1 answer

4

Try:

SELECT * FROM 'users' WHERE 'password' LIKE SHA1('admin')

Edited:

I found your problem, SHA1 returns a string of 40 characters. Since your bank has only 32. Your SHA1 (password) has been truncated. Possessing only the first 32 characters of its sequence. I recommend you change the size of the password column to 40.

    
12.09.2014 / 15:10