Get the Number of Failed Login Attempts for a Login due to a Wrong Password in SQL Server (T-SQL)

In SQL Server, you can use the LOGINPROPERTY() to return information about login policy settings.

This includes being able to return data for bad password attempts, as well as the time of the last failed login attempt due to a bad password.

BadPasswordCount

Here’s an example to demonstrate how to get the number of bad password attempts.

SELECT LOGINPROPERTY('Bart', 'BadPasswordCount');

Result:

1

In this case, it’s telling us that Bart has had one failed login attempt due to providing the wrong password.

BadPasswordTime

You can also find out the time of the last login failure due to a bad password.

SELECT LOGINPROPERTY('Bart', 'BadPasswordTime');

Result:

2020-03-29 04:06:35

PasswordLastSetTime

You can also check when the user last set the password.

SELECT LOGINPROPERTY('Bart', 'PasswordLastSetTime');

Result:

2020-03-29 03:48:16

Combined

Here they are combined into one query.

SELECT 
  LOGINPROPERTY('Bart', 'BadPasswordCount') AS Count,
  LOGINPROPERTY('Bart', 'BadPasswordTime') AS BadPasswordTime,
  LOGINPROPERTY('Bart', 'PasswordLastSetTime') AS PasswordLastSetTime;

Result:

+---------+---------------------+-----------------------+
 | Count   | BadPasswordTime     | PasswordLastSetTime   |
 |---------+---------------------+-----------------------|
 | 1       | 2020-03-29 04:06:35 | 2020-03-29 03:48:16   |
 +---------+---------------------+-----------------------+