C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Active Directory »

Encrypting Passwords from Within SQL Server


Posted Date: 10 Mar 2008    Resource Type: Code Snippets    Category: Active Directory
Author: KalyanMember Level: Gold    
Rating: 1 out of 5Points: 7





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.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Updating or deleting a single row in SQL Server
Previous Resource: How to decrypt encrypted text or password in c#.net?
Return to Discussion Resource Index
Post New Resource
Category: Active Directory


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use