Generating the Hash Generating the hash is very simple. You simply call the PWDENCRYPT function and pass the text you wish do encrypt. For example, to encrypt a variable named @Password, use the following:
PWDENCRYPT(@Password)For example, a hash generated from the word letmein is shown below. All hashes are 46 bytes long.
0x0100E3127129949737C63C686B241149E5E2A10C83BBE4D5945618643791F5B07856B50339C99DEB1AB6A3ED0FEB
Comparing Text & Hashes If you run the hashing function multiple times and have a look at the hash generated each time, you'll notice that it's completely different. Because of this, you need to use another special function, PWDCOMPARE, to test a string of text against a hash to see if it matches ? you cannot simply hash the text again and compare the two hashes. The code below compares a hash against the original password and prints the result, 1 if they match, or otherwise 0, to demonstrate the PWDCOMPARE function.
DECLARE @Hash BINARY(46) SET @Hash = 0x0100E3127129949737C63C686B241149E5E2A10C83BBE4D5945618 643791F5B07856B50339C99DEB1AB6A3ED0FEB PRINT PWDCOMPARE('letmein', @Hash)The code above also demonstrates a couple of important points. The hashes generated are in BINARY format, and are always 46 characters long. Also, if you need to use a static hash in code, it must be placed in a variable or the comparison will always fail.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|