Link to home
Start Free TrialLog in
Avatar of DJMoonLight
DJMoonLight

asked on

sp_addlogin

I am attempting to script out all my users so i can recover them if needed.  The problem is i don't remember all the passwords so i am attempting to use sp_addlogin with the skip_encryption option.

Here is what i have:

sp_addlogin 'username', 'hashedpassword', 'dbname', 'sid', 'skip_encryption'

and i get the following error:

Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.

So, then if i try:

sp_addlogin 'username', convert(varchar, 'hashedpassword', 'dbname', 'sid', 'skip_encryption'

i get the following error:

Incorrect syntax near the keyword 'convert'.

any ideas on what i am doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
From BOL

sp_addlogin [ @loginame = ] 'login'
    [ , [ @passwd = ] 'password' ]
    [ , [ @defdb = ] 'database' ]
    [ , [ @deflanguage = ] 'language' ]
    [ , [ @sid = ] sid ]
    [ , [ @encryptopt = ] 'encryption_option' ]

Arguments
[@loginame =] 'login'

Is the name of the login. login is sysname, with no default.

[@passwd =] 'password'

Is the login password. password is sysname, with a default of NULL. After sp_addlogin has been executed, the password is encrypted and stored in the system tables.

[@defdb =] 'database'

Is the default database of the login (the database the login is connected to after logging in). database is sysname, with a default of master.

[@deflanguage =] 'language'

Is the default language assigned when a user logs on to SQL Server. language is sysname, with a default of NULL. If language is not specified, language is set to the server's current default language (defined by the sp_configure configuration variable default language). Changing the server's default language does not change the default language for existing logins. language remains the same as the default language used when the login was added.

[@sid =] sid

Is the security identification number (SID). sid is varbinary(16), with a default of NULL. If sid is NULL, the system generates a SID for the new login.  Despite the use of a varbinary data type, values other than NULL must be exactly 16 bytes in length, and must not already exist. SID is useful, for example, when you are scripting or moving SQL Server logins from one server to another and you want the logins to have the same SID between servers.

[@encryptopt =] 'encryption_option'

Specifies whether the password is encrypted when stored in the system tables. encryption_option is varchar(20), and can be one of these values.