Enforcing password policy for all SQL Authentication Logins

One of my customers recently asked me how we can enforce the CHECK_POLICY option for all logins created on the SQL 2005 instance. Since by default this is enforced on a per-login basis, we cannot by default have it at a server level. But by using DDL triggers in SQL Server 2005, here is one way of achieving it:

---- BEGIN DDL Trigger Code ---  

CREATE TRIGGER trgNewLogin on all server
for create_login
 declare @loginbeingcreated sysname
 select @loginbeingcreated = eventdata().value('(/EVENT_INSTANCE/ObjectName)[1]', 'sysname')

  select 1 from sys.sql_logins
  where name = @loginbeingcreated
  and is_policy_checked = 0
  Print 'Please ensure password policy is being checked by using CHECK_POLICY'

--- END Trigger Code ---


Comments (0)

Skip to main content