Domanda

I added an item with the following SQL sentence:

INSERT INTO `db`.`users` (`name`, `pass`) VALUES ('Terry', AES_ENCRYPT('32145', '32145'))

Then the new line was added into the table, for sure.

When I tried to find this item with 'name' and 'pass',an empty set was returned. The query sentence is below:

SELECT * FROM `users` WHERE `name` ='Terry' AND `pass`= AES_ENCRYPT('32145', '32145')

Is there anything wrong with the function AES_ENCRYPT? :-(

Updates in Apr 27th, 2014:

The type of "pass" was defined as varchar(255), which turned out to be a disaster. :-(

After I modified its type as varbinary(255), everything worked.

The original problem has been solve. But, why did type varchar(255) fail in this situation?

È stato utile?

Soluzione

See this fiddle and the aes_encrypt documentation.

What type is your pass column? on the fiddle I defined it like:

pass varbinary(200)

Did this insert successfully:

INSERT INTO users (name, pass) VALUES ('Terry', aes_encrypt('32145', '32145'))

Then queried it like this:

select * 
from users 
where name = 'Terry' and pass = aes_encrypt('32145', '32145');

select *, aes_decrypt(pass, '32145') 
from users 
where pass = aes_encrypt('32145', '32145');

So your query should have worked.

Altri suggerimenti

SELECT * FROM users WHERE name ='Terry' AND pass= AES_DECRYPT('32145', '32145')

MySQL Reference

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top