Groups | Blog | Home
all groups > sql server (alternate) > october 2004 >

sql server (alternate) : encrypt(string) Question!!


rrey2279 NO[at]SPAM aol.com
10/28/2004 9:01:08 AM
SQL Server 2000:

########################################################
I run the following as a normal query from Analyzer:
########################################################

SELECT encrypt(user_password) FROM emp WHERE user_id = 1

#########################################################
I run the following query from inside a stored proc:
#########################################################

SELECT encrypt(user_password) FROM emp WHERE user_id = 1

#########################################################
Question????
#########################################################

If the data inside the emp table does not change, how can these two
queries return different values?

Any help would be much appreciated!

thanks,
James Goodwin
10/28/2004 3:26:51 PM
[quoted text, click to view]

They return different values because the encrypt function 'salts' the data
to prevent someone from just encrypting a bunch of stuff to figure out the
other data in the table.

The Unix crypt function used to do this by putting two random characters on
the front of the data string and also on the front of the encryption string
using the 'salt' as part of the key.

Regards,
Jim


David Portas
10/28/2004 8:42:12 PM
In addition to James's reply, note that the Encrypt function is undocumented
so its behaviour can change between versions of the product. Don't rely on
it in production code. Generate a password hash client-side would be my
suggestion.

--
David Portas
SQL Server MVP
--

Greg D. Moore (Strider)
10/28/2004 11:45:11 PM

[quoted text, click to view]

And in the at least one case I looked at, trivial to decrypt.


[quoted text, click to view]

AddThis Social Bookmark Button