LOGINPROPERTY (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![no](media/no.png)Azure SQL Database ![no](media/no.png)Azure SQL Data Warehouse ![no](media/no.png)Parallel Data Warehouse

Returns information about login policy settings.

Topic link icon Transact-SQL Syntax Conventions

Syntax

  
LOGINPROPERTY ( 'login_name' , 'property_name' )  

Arguments

login_name
Is the name of a SQL Server login for which login property status will be returned.

propertyname
Is an expression that contains the property information to be returned for the login. propertyname can be one of the following values.

Value Description
BadPasswordCount Returns the number of consecutive attempts to log in with an incorrect password.
BadPasswordTime Returns the time of the last attempt to log in with an incorrect password.
DaysUntilExpiration Returns the number of days until the password expires.
DefaultDatabase Returns the [!INCLUDEssNoVersion] login default database as stored in metadata or master if no database is specified. Returns NULL for non-[!INCLUDEssNoVersion] provisioned users (for example, Windows authenticated users).
DefaultLanguage Returns the login default language as stored in metadata. Returns NULL for non-[!INCLUDEssNoVersion] provisioned users, for example, Windows authenticated users.
HistoryLength Returns the number of passwords tracked for the login, using the password-policy enforcement mechanism. 0 if the password policy is not enforced. Resuming password policy enforcement restarts at 1.
IsExpired Indicates whether the login has expired.
IsLocked Indicates whether the login is locked.
IsMustChange Indicates whether the login must change its password the next time it connects.
LockoutTime Returns the date when the [!INCLUDEssNoVersion] login was locked out because it had exceeded the permitted number of failed login attempts.
PasswordHash Returns the hash of the password.
PasswordLastSetTime Returns the date when the current password was set.
PasswordHashAlgorithm Returns the algorithm used to hash the password.

Returns

Data type depends on requested value.

IsLocked, IsExpired, and IsMustChange are of type int.

BadPasswordCount and HistoryLength are of type int.

BadPasswordTime, LockoutTime, PasswordLastSetTime are of type datetime.

PasswordHash is of type varbinary.

NULL if the login is not a valid SQL Server login.

DaysUntilExpiration is of type int.

PasswordHashAlgorithm is of type int.

Remarks

This built-in function returns information about the password policy settings of a SQL Server login. The names of the properties are not case sensitive, so property names such as BadPasswordCount and badpasswordcount are equivalent. The values of the PasswordHash, PasswordHashAlgorithm, and PasswordLastSetTime properties are available on all supported configurations of SQL Server SQL Server but the other properties are only available when SQL Server SQL Server SQL Server is running on SQL Server SQL Server SQL Server Windows Server 2003 and both CHECK_POLICY and CHECK_EXPIRATION are enabled. For more information, see Password Policy.

Permissions

Requires VIEW permission on the login. When requesting the password hash, also requires CONTROL SERVER permission.

Examples

A. Checking whether a login must change its password

The following example checks whether SQL Server login John3 must change its password the next time it connects to an instance of SQL Server SQL Server

SELECT LOGINPROPERTY('John3', 'IsMustChange');  
GO  

B. Checking whether a login is locked out

The following example checks whether SQL Server login John3 is locked.

SELECT LOGINPROPERTY('John3', 'IsLocked');  
GO  

See Also

CREATE LOGIN (Transact-SQL)
sys.server_principals (Transact-SQL)