http://www.sqlservercentral.com/blogs/basits-sql-server-tips/2012/07/10/retrieving-password-policy-settings-for-sql-login-accounts/

Printed 2014/08/01 11:16AM

Retrieving password policy settings for SQL login accounts

2012/07/10

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.



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