Solved

How to use Transact SQL 'pwdcompare' ?

Posted on 1998-11-23
9
1,147 Views
Last Modified: 2011-10-03
Need to know how SQL handles the statement SELECT PWDCOMPARE(@password1, @password2).

I always get the same result ( 0 ) whether my passwords are the same or not.  Pls help!
0
Comment
Question by:SpaarQ
  • 6
  • 3
9 Comments
 
LVL 7

Accepted Solution

by:
tchalkov earned 300 total points
ID: 1091933
the first argument of pwdcompare is the clear text password, the second argument is the encoded password sql server stores in syslogins. You can see the encoded password by using 'select * from syslogins' in database master
0
 

Author Comment

by:SpaarQ
ID: 1091934
Thanks, but what I am trying to do is to save an encrypted password using PWDENCRYPT to my table and compare it with  another string.  Please let me know if this is possible in MS SQL.

e.x.

DECLARE @pwd1 char(8)
DECLARE @pwd2 char(8)

SELECT  @pwd1  = PWDENCRYPT('password')
SELECT  @pwd2  = 'password'

SELECT PWDCOMPARE(@pwd2, @pwd1)


Result is 0.

I am defining a set of users to my users table and would like to encrypt the password so it will not be readable.


Thanks.

0
 

Author Comment

by:SpaarQ
ID: 1091935
Adjusted points to 200
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 7

Expert Comment

by:tchalkov
ID: 1091936
yes it is possible but you have a mistake in the code above - the encrypted password is at least 16 chars long - so declare your variables as char(16) and the code will work. however i am not sure if this is enough. you have to try.
0
 

Author Comment

by:SpaarQ
ID: 1091937

i have tried adjusting the sizes but i need to know what value should i expect if the two passwords match or do not match.

i have increased the points to 300. Please tell me how to decrypt , if possible an encrypted password.  I intend to display the original password(hidden with **** chars, of course) on my screen.  Also, compare my new password with my old password in case I wish to change it.

0
 

Author Comment

by:SpaarQ
ID: 1091938
Adjusted points to 300
0
 
LVL 7

Expert Comment

by:tchalkov
ID: 1091939
The password field in the syslogins table is 30 chars wide so you can be sure that the encrypted password will be less or equal than 30 characters. However I think that 16 is absolutely enough because always the output of pwdencrypt is 16 chars wide, but there is no documentation so 30 is a safe choice.
pwdcompare returns 0 if passwords do not much or 1 if they match.
there is no way to decrypt. this is a one-way encryption(as far as i know). the only way is to use pwdcompare or a brute force attack if you want to know the original password.
There is a good article about password encryption in SQL Server on: http://www.winntmag.com/magazine/article.cfm?ArticleID=102

0
 

Author Comment

by:SpaarQ
ID: 1091940
Thanks for the great help.

I was having problems updating this yesterday, and i tried to locate your email address since you were very quick answering my questions..

Thank you very much fo the effort.


0
 

Author Comment

by:SpaarQ
ID: 1091941
Thanks for the great help.

I was having problems updating this yesterday, and i tried to locate your email address since you were very quick answering my questions..

Thank you very much fo the effort.


0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access denied running PowerPivot -SQL Server 2014 on Windows Server 2012 10 28
SQL Server Designer 19 39
Simple SQL query from two tables 13 52
hyperlink data type in SQL 3 26
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question