If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Encrypting password column in T-SQL?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-09, 16:56
ppalubinski ppalubinski is offline
Registered User
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 44
Encrypting password column in T-SQL?

Hi Folks,

I'm trying to create a table in my database to contain user login info. In MySQL, there were some functions you could use to encrypt the data that went into the password column. Is there similar functions in T-SQL? If so, what is the most convenient way to encrypt the passwords stored in the DB and decrypt them when requested from an outside programming procedure (such as in ASP.NET)? Any suggestions would be greatly appreciated.

Regards,

Paul
__________________
Paul Palubinski
Reply With Quote
  #2 (permalink)  
Old 01-29-09, 10:18
MCrowley MCrowley is offline
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 4,899
SQL Server 2005 and SQL Server 2008 have a lot of encryption options. You can start here for SQL Server 2008. Most of the concepts are the same between the two, but SQL Server 2008 expanded on the actual functions a bit.
Reply With Quote
  #3 (permalink)  
Old 01-30-09, 00:38
ppalubinski ppalubinski is offline
Registered User
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 44
Thanks for the response. I just took a quick look at that article, but it seems to be what I need.
__________________
Paul Palubinski
Reply With Quote
  #4 (permalink)  
Old 01-30-09, 04:13
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
By the by, you shouldn't need to decrypt your passwords... You take the entered value, encrypt it, and then compare this derivation to the stored encrypted password.
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 01-30-09, 09:36
MCrowley MCrowley is offline
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 4,899
Ahh, georgev, georgev, georgev. Some day, you will learn that the word "should" bites you more often than anyone else.
Code:
if not exists (select * from sys.symmetric_keys where name = '##MS_DatabaseMasterKey##')
  begin 
	create master key encryption by password = 'Here is a database master key!'
  end

create asymmetric key UserKey with algorithm = RSA_512

select EncryptByAsymKey (AsymKey_ID('UserKey'), 'Georgev should not assume')
select EncryptByAsymKey (AsymKey_ID('UserKey'), 'Georgev should not assume')
select EncryptByAsymKey (AsymKey_ID('UserKey'), 'Georgev should not assume')
select EncryptByAsymKey (AsymKey_ID('UserKey'), 'Georgev should not assume')
Now, encode it 50 more times on the blackboard, young man.
Reply With Quote
  #6 (permalink)  
Old 01-30-09, 09:58
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
DECLARE @i int
    SET @i = 1

WHILE @i <= 50
  BEGIN
    PRINT EncryptByAsymKey (AsymKey_ID('UserKey'), 'Georgev should not assume')

    SET @i = @i + 1
  END
__________________
George
Twitter | Blog
Reply With Quote
  #7 (permalink)  
Old 02-18-09, 07:41
Doron_ Doron_ is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
The CHECKSUM function does it simply.

the code:

Quote:
SELECT CHECKSUM('my string')

returns a number which is a one-directional encrytion of the given string.



Nob Hill Software - tools for database people (+ free stuff!) Nob Hill Software - tools for database people (+ free stuff!)
http://www.nobhillsoft.com
Reply With Quote
  #8 (permalink)  
Old 02-18-09, 09:42
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
No, not really.
And Good Lord, if you are going to do that then at least use BinaryChecksum.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #9 (permalink)  
Old 02-18-09, 10:22
MCrowley MCrowley is offline
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 4,899
I never thought of using checksum. Probably because the results of the function are not unique. Although, this would give you the ability to better guess the password, since there are multiple variations that will generate the same checksum, and therefore grant you access. Better yet, if you have access to the checksum column, you can make an educated guess as to the password.
Reply With Quote
  #10 (permalink)  
Old 02-18-09, 10:24
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Yeah - I believe Peso reverse engineered sql server checksum.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #11 (permalink)  
Old 02-18-09, 13:44
ppalubinski ppalubinski is offline
Registered User
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 44
I ended up using ENCRYPTBYASYMKEY() and in terms of awesomeness, it was the opposite of Colin Farrell's performance in the movie, Dare Devil. Thanks for all the assistance folks.
__________________
Paul Palubinski
Reply With Quote
  #12 (permalink)  
Old 02-18-09, 21:21
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Quote:
Originally Posted by ppalubinski
I ended up using ENCRYPTBYASYMKEY() and in terms of awesomeness, it was the opposite of Colin Farrell's performance in the movie, Dare Devil. Thanks for all the assistance folks.
Best practice is not to encrypt passwords at all. Passwords should be hashed (use the HashBytes function). In that respect George was correct: hash the password and compare hashes, don't compare passwords.

The only reason to encrypt a password is if you require recovery of the original password. Password recovery is itself a weakness and ideally passwords should be unrecoverable. Note that password complexity rules are also important to make sure the password can't be recovered using a password dictionary attack.
Reply With Quote
  #13 (permalink)  
Old 02-18-09, 21:34
ppalubinski ppalubinski is offline
Registered User
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 44
To be honest, I probably don't need to apply a hash or password checker for this project. I would be deeply honored if someone decided it was worthwhile to try crack the system we're working on. And I'm sure the achievement would be more disappointing than a Colin Farrell movie.
__________________
Paul Palubinski
Reply With Quote
  #14 (permalink)  
Old 02-18-09, 21:50
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Here's the problem however. If you implement password authentication with only trivial security and from which passwords are recoverable then two things will happen. Firstly, you will deceive legitimate users into thinking their data is secure. Secondly, a determined attacker may be able to identify a user and recover the user's password. Chances are that user has used the same password or derivations of it elsewhere - possibly for more sensitive or important data than your system holds. Determined attackers know this and may target the weakest-link systems to get at those passwords. So as a consequence of your system's weaknesses you could make other data vulnerable too.

In my opinion that is why every system should implement best practice password management and the user should never be swindled by a system that looks secure when it actually isn't.
Reply With Quote
  #15 (permalink)  
Old 02-18-09, 21:54
ppalubinski ppalubinski is offline
Registered User
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 44
Fair enough, but we determine the passwords for our clients and the data is our own data that they are just allowed to view, but I'll definitely look into using a hash algorithm to get into a good habit.
__________________
Paul Palubinski
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On