gpt4 book ai didi

sql - 从 SQL 登录中提取密码

转载 作者:行者123 更新时间:2023-12-04 05:49:51 25 4
gpt4 key购买 nike

我需要编写一个脚本来提取 SQL 登录的密码并将其传播到另一台服务器。

我这样做了:

Declare @PasswordBinary varbinary(256)
Set @PasswordBinary = CAST(LOGINPROPERTY( @LoginName, 'PasswordHash' ) AS varbinary (256))

Exec sp_hexadecimal @PasswordBinary, @PasswordStr Out

sp_十六进制:
Create PROCEDURE [dbo].[sp_hexadecimal]
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)

SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'

WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int

SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)

SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)

SELECT @i = @i + 1
END

SELECT @hexvalue = @charvalue

我有一个变量
@SQL nvarchar(max) = 'CREATE LOGIN ' + QUOTENAME(@LoginName) + ' With PASSWORD = ' + @PasswordStr + ' HASHED'''

我将它发送到远程服务器上的存储过程,然后在那里执行这个变量:
 Exec (@SQL)

但我有一个错误:

The @SQL variable is set to : 'Create Login [Name] With password = 0x Hashed'



谢谢 :)

最佳答案

更改程序以在密码上添加引号:

SET @tmpstr = 'CREATE LOGIN [' + @name + '] WITH PASSWORD=' + @txtpwd + ' HASHED' 

关于sql - 从 SQL 登录中提取密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10208884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com