Printed 2015/10/08 02:37PM

Retrieving password policy settings for SQL login accounts


Today, I wrote the following query for our internal audit report for SAS70. This query provides all the necessary details about SQL Logins policy settings.

This query is using LOGINPROPERTY function to retrieve the sql login policy settings information:

USE [master]

DECLARE @PwdExpirationAge    [int]

SET @PwdExpirationAge = 28

SELECT [name] AS [sa]
      ,LOGINPROPERTY([name], 'PasswordLastSetTime') AS [PasswordLastResetDT]
      ,@PwdExpirationAge - DATEDIFF(DAY, CONVERT([datetime] 
        ,GETDATE()) AS [DaysUntilExpiration]
      ,LOGINPROPERTY([name], 'BadPasswordCount') AS [BadPasswordCount]
      ,LOGINPROPERTY([name], 'BadPasswordTime') AS [BadPasswordDT]
      ,LOGINPROPERTY([name], 'HistoryLength') AS [HistoryLength]
      ,LOGINPROPERTY([name], 'IsExpired') AS [IsExpired]
      ,LOGINPROPERTY([name], 'IsLocked') AS [IsLocked]
      ,LOGINPROPERTY([name], 'IsMustChange') AS [IsMustChange]
      ,LOGINPROPERTY([name], 'LockoutTime') AS [LockoutTime]
FROM [sys].[sql_logins]
GROUP BY [name]

I hope you will find this query useful.

Copyright © 2002-2015 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.