• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1092
  • Last Modified:

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?
0
DJMoonLight
Asked:
DJMoonLight
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hi DJMoonLight,
> sp_addlogin 'username', 'hashedpassword', 'dbname', 'sid', 'skip_encryption'


this will do it, sp_addlogin     @loginame = 'username',
        @passwd ='hashedpassword',
        @defdb='dbname',
                @encryptopt= 'skip_encryption'


Aneesh
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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.

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now