ALTER LOGIN (Transact-SQL)
Changes the properties of a SQL Server login account.
ALTER LOGIN login_name
{
<status_option>
| WITH <set_option> [ ,... ]
| <cryptographic_credential_option>
}
<status_option> ::=
ENABLE | DISABLE
<set_option> ::=
PASSWORD = 'password' | hashed_password HASHED
[
OLD_PASSWORD = 'oldpassword'
| <password_option> [<password_option> ]
]
| DEFAULT_DATABASE = database
| DEFAULT_LANGUAGE = language
| NAME = login_name
| CHECK_POLICY = { ON | OFF }
| CHECK_EXPIRATION = { ON | OFF }
| CREDENTIAL = credential_name
| NO CREDENTIAL
<password_option> ::=
MUST_CHANGE | UNLOCK
<cryptographic_credentials_option> ::=
ADD CREDENTIAL credential_name
| DROP CREDENTIAL credential_name
When CHECK_POLICY is set to ON, the HASHED argument cannot be used.
When CHECK_POLICY is changed to ON, the following behavior occurs:
CHECK_EXPIRATION is also set to ON, unless it is explicitly set to OFF.
The password history is initialized with the value of the current password hash.
When CHECK_POLICY is changed to OFF, the following behavior occurs:
CHECK_EXPIRATION is also set to OFF.
The password history is cleared.
The value of lockout_time is reset.
If MUST_CHANGE is specified, CHECK_EXPIRATION and CHECK_POLICY must be set to ON. Otherwise, the statement will fail.
If CHECK_POLICY is set to OFF, CHECK_EXPIRATION cannot be set to ON. An ALTER LOGIN statement that has this combination of options will fail.
Important |
|---|
CHECK_EXPIRATION and CHECK_POLICY are only enforced on Windows Server 2003 and later. For more information see Password Policy. |
Important |
|---|
A known issue in Windows Server 2003 might prevent the bad password count from resetting after the Account Lockout threshold has been reached. This could cause an immediate lockout on subsequent failed login attempts. You can manually reset the bad password count by briefly setting CHECK_POLICY = OFF, followed by CHECK_POLICY = ON. For more information about the Account Lockout threshold, see Microsoft Knowledge Base article 818078: Your User Account May Be Prematurely Locked Out. |
You cannot use ALTER_LOGIN with the DISABLE argument to deny access to a Windows group. For example, ALTER_LOGIN [domain\group] DISABLE will return the following error message:
"Msg 15151, Level 16, State 1, Line 1
"Cannot alter the login 'Domain\Group', because it does not exist or you do not have permission."
This is by design.
Requires ALTER ANY LOGIN permission.
If the CREDENTIAL option is used, also requires ALTER ANY CREDENTIAL permission.
If the login that is being changed is a member of the sysadmin fixed server role or a grantee of CONTROL SERVER permission, also requires CONTROL SERVER permission when making the following changes:
Resetting the password without supplying the old password.
Enabling MUST_CHANGE, CHECK_POLICY, or CHECK_EXPIRATION.
Changing the login name.
Enabling or disabling the login.
Mapping the login to a different credential.
A principal can change the password, default language, and default database for its own login.
A. Enabling a disabled login
The following example enables the login Mary5.
ALTER LOGIN Mary5 ENABLE;
B. Changing the password of a login
The following example changes the password of login Mary5 to a strong password.
ALTER LOGIN Mary5 WITH PASSWORD = '<enterStrongPasswordHere>';
C. Changing the name of a login
The following example changes the name of login Mary5 to John2.
ALTER LOGIN Mary5 WITH NAME = John2;
D. Mapping a login to a credential
The following example maps the login John2 to the credential Custodian04.
ALTER LOGIN John2 WITH CREDENTIAL = Custodian04;
E. Mapping a login to an Extensible Key Management credential
The following example maps the login Mary5 to the EKM credential EKMProvider1.
ALTER LOGIN Mary5 ADD CREDENTIAL EKMProvider1; GO
F. Unlocking a login
To unlock a SQL Server login, execute the following statement, replacing **** with the desired account password.
ALTER LOGIN [Mary5] WITH PASSWORD = '****' UNLOCK ; GO
To unlock a login without changing the password, turn the check policy off and then on again.
ALTER LOGIN [Mary5] WITH CHECK_POLICY = OFF; ALTER LOGIN [Mary5] WITH CHECK_POLICY = ON; GO
G. Changing the password of a login using HASHED
The following example changes the password of the TestUser login to an already hashed value.
ALTER LOGIN TestUser WITH PASSWORD = 0x01000CF35567C60BFB41EBDE4CF700A985A13D773D6B45B90900 HASHED ; GO