Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
efelito
Constraint Violating Yak Guru
478 Posts |
Posted - 2002-01-31 : 17:58:24
|
quote: CREATE PROCEDURE spadmin_util_ScriptLogins /********************************************************************************//* Stored Procedure: spadmin_util_ScriptLogins *//* Creation Date: 01/22/2002 *//* Written by: Jeff Banschbach *//* Consultant, MCDBA *//* Greenbrier & Russel *//* *//* Purpose: Generates a script that can be used to recreate all *//* logins on a server. This script stores passwords in an *//* encrypted format. *//* *//* Input Paramters: None *//* *//* Output Parameters: None *//* *//* Return Status: None *//* *//* Usage *//* exec spadmin_util_ScriptLogins *//* ex: exec spadmin_util_ScriptLogins *//* *//* Local Variables: *//* @loginname - Cursor Variable for current loginname *//* @binpass - Cursor Variable for current password in binary form *//* @charpass - Encrypted Binary password in Char form *//* @dbname - Cursor Variable for current users default database *//* @language - Cursor Variable for current users default language *//* @i - Loop Variable *//* @length - Loop Variable *//* @hexstring - Temp hex value *//* @tempint - Placeholder *//* @firstint - Placeholder *//* @secondint - Placeholder *//* *//* Called By: *//* SQL Server Job *//* *//* Calls: *//* spadmin_util_hexadecimal *//* *//* Updates: *//* Date Author Purpose *//* *//********************************************************************************/AS----Declare Local VariablesDECLARE @loginname sysnameDECLARE @binpass varbinary(255)DECLARE @charpass varchar(255)DECLARE @dbname sysnameDECLARE @language sysnameDECLARE @i intDECLARE @length intDECLARE @hexstring char(16)DECLARE @tempint intDECLARE @firstint intDECLARE @secondint intSET NOCOUNT ON----Generate Script to Add NT Groups and NT Users then Set Their Default DatabaseSELECT 'exec master.dbo.sp_grantlogin "' + sl.loginname + '"' + char(13) + 'GO' + char(13) + 'exec master.dbo.sp_defaultdb "' + sl.loginname + '", "' + sl.dbname + '"' + char(13) + 'GO' + char(13)FROM master.dbo.syslogins slWHERE isntuser = 1 or isntgroup = 1----Declare Cursor to Store List of SQL Server LoginsDECLARE user_cursor CURSOR FOR SELECT loginname, convert(varbinary(32), password), dbname, language FROM master.dbo.syslogins WHERE isntuser = 0 and isntgroup = 0OPEN user_cursorFETCH NEXT FROM user_cursor INTO @loginname, @binpass, @dbname, @languageWHILE @@fetch_status = 0BEGIN ----Generate Script to Add SQL Server Logins with their Default Database and Language-- EXEC admin.dbo.spadmin_util_hexadecimal @binpass, @charvalue = @charpass OUTPUT SELECT @charpass = '0x' SELECT @i = 1 SELECT @length = datalength(@binpass) SELECT @hexstring = '0123456789abcdef' WHILE (@i <= @length) BEGIN SELECT @tempint = convert(int, substring(@binpass,@i,1)) SELECT @firstint = floor(@tempint/16) SELECT @secondint = @tempint - (@firstint*16) SELECT @charpass = @charpass + substring(@hexstring, @firstint+1, 1) + substring(@hexstring, @secondint+1, 1) SELECT @i = @i + 1 end SELECT 'exec master.dbo.sp_addlogin "' + @loginname + '", ' + @charpass + ', "' + @dbname + '", "' + @language + '", @encryptopt = "skip_encryption"' + char(13) + 'GO' + char(13) FETCH NEXT FROM user_cursor INTO @loginname, @binpass, @dbname, @languageEND----Clean Up Cursor VariableCLOSE user_cursorDEALLOCATE user_cursorSET NOCOUNT OFF
Edited by - efelito on 01/31/2002 17:59:28 |
|
|
|
|
|
|