faqts : Computers : Databases : MySQL : Language and Syntax : Queries : Mathematical Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 10 people (100%) answered Yes
Recently 6 of 6 people (100%) answered Yes

Entry

Why can't I get ENCRYPT() to match identical passwords?
What is the effect of the salt in ENCRYPT()?

May 10th, 2000 20:01
Nathan Wallace, Tim Smith


Encrypt uses a "salt"; if you don't specify the salt, it'll pick one for
you (not the same one each time).  So you need to specify the same salt
both when you encrypt and decrypt.  The salt shows up as the first two
characters in the crypted password.  So you could do:

    select * from user where
        password = encrypt('password', substring(password from 1 for 2))

You might want to look at the md5() function, too.