The Login_CreateLogin() function is used to create a new SQL login.
Login_CreateLogin(data_source, user_ID, password, login_options, return_code)
• data_source – A string specifying the data source to use to connect to the SQL server.
• user_ID – A string specifying the ID of the user login that is being created.
• password – An string that specifies the password to use for the SQL login.
• login_options – A long integer that specifying the option settings to use for the SQL login. This is a bitmask value. The following table lists the options and their corresponding hexadecimal values:
Option |
Value |
---|---|
Enforce password policy |
0x01000000 |
Enforce password expiration |
0x02000000 |
Change password on next login |
0x00800000 |
These options apply only to logins for SQL Server 2005. They are ignored for SQL Server 2000. |
• return_code – A returned long integer indicating the results of the command. This is a bitmask value. The following table lists the values that can be returned.
Return code |
Value |
---|---|
Successful login |
0x00000001 |
Failed login |
0x00000002 |
Create or alter failed |
0x00000004 |
Create or alter succeeded |
0x00000008 |
Password expired |
0x00010000 |
Exception caught |
0x00020000 |
Login locked |
0x00040000 |
Password too short |
0x00100000 |
Password too long |
0x00200000 |
Password not complex |
0x00400000 |
An integer specifying the status of the operation. The following table lists the constants that correspond to the values that can be returned.
Constant |
Description |
---|---|
STATUS_SUCCESS |
Operation was successful. |
STATUS_MEMORY_ERROR |
A memory error occurred. |
STATUS_TOO_MANY_CONNECTIONS |
Too many SQL connection in use to perform the operation. |
STATUS_DATASOURCE_REJ |
The SQL server rejected the operation. |
STATUS_UNABLE_TO_CONNECT |
Unable to connect to the data source. |
STATUS_LOGIN_LOCKED |
Login is locked. |
STATUS_LOGIN_PASSWORD_HISTORY |
Password supplied violates password history. |
STATUS_LOGIN_PASSWORD_SHORT |
Password specified is too short. |
STATUS_LOGIN_PASSWORD_LONG |
Password specified is too long. |
STATUS_LOGIN_PASSWORD_SIMPLE |
Password specified is too simple. |
STATUS_LOGIN_PASSWORD_UNKNOWN |
Password is unknown. |
STATUS_LOGIN_EXISTS |
The login already exists. |
STATUS_LOGIN_PASSWORD_POLICY |
The password specified violates the password policy. |
STATUS_LOGIN_INVALID |
The login is not valid to perform the operation. |
STATUS_INVALID_PERMISSIONS |
The login had invalid permissions to perform the operation. |
STATUS_NOT_LOGGED_IN |
No user is logged in to perform the operation. |
The current user must have SQL administrative privileges to create a new login.