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]
GO
DECLARE @PwdExpirationAge    [int]
SET @PwdExpirationAge = 28
SELECT [name] AS [sa]
      ,LOGINPROPERTY([name], 'PasswordLastSetTime') AS [PasswordLastResetDT]
      ,@PwdExpirationAge - DATEDIFF(DAY, CONVERT([datetime] 
        ,LOGINPROPERTY([name],'PasswordLastSetTime'))
        ,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.

Rate

Share

Share

Rate