Select in encrypted value

Asked

Viewed 71 times

2

Well, I created a table and entered a value into a field using SHA1(Encrypt), and I don’t know how to select the value by this 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 so:

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

Returns:

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

Does anyone know how? Thank you.

  • 1

    password must be 40 characters, not 32.

1 answer

4


Try:

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

Edited:

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

  • Mysql did not return any record. (Query took 0.0020 sec) :C

  • Thanks, it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.