Find Weak Database Passwords

T-SQL stored procedure checks passwords' complexity

Downloads
99987.zip

The usp_Check_Passwords stored procedure is a simple T-SQL password-cracking tool that you can use to check the complexity of the passwords used for SQL Server database logins. This stored procedure requires access to the passwd column of the syslogins system table in the master database. It is unlikely that a hacker will gain access to the syslogins table, but nonetheless it’s a useful tool for finding weak passwords.

The stored procedure takes one parameter: the pathname of a text file containing passwords. It uses the BULK INSERT statement executed dynamically to load the password file into SQL Server. Password files can be obtained from a number of places on the web. Alternatively, you can write your own password file. Simply put each password on a separate line and save the password list as a text file. Figure 4 shows an example of a simple password file named Pswfile.txt. To use this file with usp_Check_Passwords, you’d use the code

USE master GOEXEC usp_check_passwords   'C:\temp\pswfile.txt'

Note that you’d need to customize the password file’s path.

The stored procedure uses the undocumented PWDCompare system function to compare each passed-in password against the passwd column in the syslogins table. The procedure will also detect blank passwords and trivial logins (i.e., logins that have the same password as their login name).

I wrote and checked usp_Check_Passwords on SQL Server 2005 Developer Edition SP1. You can download the code for this stored procedure by clicking the 99987.zip hotlink at the top of this page.

—Eli Leiba, senior application DBA, Israel Electric

Discuss this Article 2

majormojo
on Oct 2, 2008
Thanks for the code. This works good for trivial passwords, but after I created a login with a blank password using Management Studio (on SQL 2000 & 2005 instances), it doesn't show up on the report when I run this. After creating a login with blank password using Enterprise Manager on a SQL 2000 instance, that login shows up as NULL password on the report. Examining the syslogins table, Management Studio apparently doesn't store the password as 'NULL', even though when logging on with that account, a blank password works. Can you modify the code for this? Thanks.
majormojo
on Oct 2, 2008
Oh, yeah, I added the following at the end of the select statement to exclude the Certificate logins: and syslogins.name NOT LIKE '##MS_%##'

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.