views:

24

answers:

1

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?

+1  A: 

If you use encrypt() with no salt, a random salt (2 letter) is generated and added to the encrypted string.

On subsequent calls, you need to pass the same salt to the ENCRYPT. You can just pass the whole encrypted string as salt,

   encrypt(user_input, encrypted_password) = encrypted_password
ZZ Coder
thanks, that was it.
contagious