Password Audit for SQL Server Logins

Who is online?  367 guests and 0 members
home  »  articles  »  Password Audit for SQL Server Logins

Password Audit for SQL Server Logins

change text size: A A A
Published: 12/6/2011 11:43:54 PM by  Sarabpreet Anand  - Views:  [45306]

Password audit is a must for all SQL Servers. Weak or Blank passwords are invitation to trouble and such type of passwords may result in security breach. Everybody knows the importance of Strong and Complex password but as they say it’s always easy to preach but difficult to practice, we tend to make use of weak and sometimes blank passwords. Now the question arises how to get rid of these.

Regular Password Audits is the solution. As a SQL DBA we must do a regular audit and remind the users to change their passwords to something more complex. In this article I’ll explain you how to do password audit and how to customize it according to your environment. For understanding Password Auditing, you need to understand the built-in function PWDCOMPARE


       This function hashes a password and compares the hash to the hash of existing password. You must be wondering why are we again hashing, SQL Server stores the Hash of password for SQL Logins and hashing is only one side, un-hashing or decrypting the hashed data is not at all possible. This function is available from SQL Server 7.0 to SQL Server 2012 i.e., Denali, means you can make use of this function in all SQL Server versions.

The function takes 3 parameters Clear_test_password, Password_Hash and Version where the first two are mandatory and the third one is optional and obsolete but it is there for backward compatibility. It returns 1 if the hash of the clear_text_password matches the password_hash parameter, and 0 if it does not.

Note: PWDCOMPARE function is not a threat against the strength of password hashes because the same test could be performed by trying to log in using the password provided as the first parameter.

Permissions required: PWDENCRYPT is available to public and CONTROL SERVER permission is required to examine the password_hash column of sys.sql_logins.


A. Identifying logins that have no passwords

The following example identifies SQL Server logins that have no passwords.

SELECT name FROM sys.sql_logins
WHERE PWDCOMPARE('', password_hash) = 1 ;


 B. Searching for passwords which are same as login names

This code identifies the login where the user has given the same text as login and password, for example Login Payroll_web_User is a login with password Payroll_web_User

SELECT name FROM sys.sql_logins
WHERE PWDCOMPARE(name, password_hash) = 1 ;


 C Searching for common passwords

To search for common passwords that you want to identify and change, specify the password as the first parameter. This will check for a password specified as password.

SELECT name FROM sys.sql_logins
WHERE PWDCOMPARE('password', password_hash) = 1 ;


Hope this post helped you, do leave comments.

If you liked the posts, do like us on Facebook at


Sarabpreet Singh

tags : blank password, how to find, password, sql 2012, SQL denali, SQL Login Strength Audit, weak password
  To rate this article please  register  or  login


Sarabpreet Anand Sarabpreet Anand (Member since: 3/15/2011 5:38:06 AM)
SQLServer-MVP, Vice President -

Sarabpreet is SQLServer MVP, DBA, Speaker, Trainer, Blogger and Community Lead. You can find him speaking at a local UG Event or a SQL Webcast. He has 8+ years of Experience and worked with Industry Leaders like Wipro, HP and HCL. He has many SQL Certifications under his belt. His core competency lies in administration of SQL Server. Always ready to help, online \offline. His life’s mantra is “Knowledge Increases by sharing so, Pass it on”. To know about his speaking engagements visit: here...

Follow Sarab on  Twitter@Sarab_SQLGeek ,  Facebook ,  LinkedIn

Comments (1)

12/29/2011 10:58:09 AM Ritesh Medhe said:



Leave a comment

Email:  (your email is kept secure)

example: ""

Type the characters:

SQLServerGeeks FaceBook group

SQLServerGeeks Events

Training on Microsoft Products & Technologies

Email Subscriptions

   Get the Most Recent Blogs in your inbox
Articles RSS Feed

Most Recent Articles