compare previous ENCRYPT() call with new ENCRYPT() call mysql

Posted by contagious on Stack Overflow See other posts from Stack Overflow or by contagious
Published on 2010-05-05T03:46:41Z Indexed on 2010/05/05 3:48 UTC
Read the original article Hit count: 357

Filed under:
|
|

I'm storing a string in mysql with the ENCRYPT() function. I want to fetch a row where that string is matched, but the new ENCRYPT() call gives me a different value, so they never match.

This is expected as i'm not (and can't) give it a consistent salt: http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_encrypt

If no salt argument is given, a random value is used.

This is the query i'm running that returns empty:

SELECT * FROM `table` WHERE ENCRYPT('string') = `enc_string`

I know this is possible because this is used by a 3rd party app, but I can't find their query where they do this. Is there a way to force ENCRYPT to use the previous salt, or predict it?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query