为什么,PWDCOMPARE返回0,应该返回1? [英] Why is , PWDCOMPARE is returning 0, when it should be returning 1?

查看:90
本文介绍了为什么,PWDCOMPARE返回0,应该返回1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @original nvarchar(128)  = '1'
declare @afterhash varbinary(128) = HASHBYTES('SHA2_512', '1')

select PWDCOMPARE(@original, @afterhash)
select @afterhash





我尝试了什么:



我试图将1更改为0并将1更改为@original。



What I have tried:

I have tried to change 1 to 0 and change 1 to @original.

解决方案

它返回0,因为PWDCOMPARE正在使用非SHA2_512算法传入您传入的明文密码。



您可以通过以下方式自行查看:

It's returning 0 because PWDCOMPARE is hashing the clear text password you're passing in with an algorithm that is not SHA2_512.

You can see this yourself by doing this:
DECLARE @Original nvarchar(128) = '1';

DECLARE @Hashed varbinary(128) = HASHBYTES('SHA2_512', '1');

SELECT PWDENCRYPT(@Original) AS 'PWDENCRYPT Hash';
SELECT @Hashed AS 'SHA2_512 Hash';

SELECT PWDCOMPARE(@Original, @Hashed);





你应该只使用PWDCOMPARE一列用PWDENCRYPT加密。



你不应再被PWDENCRYPT了。请改用HASHBYTES并自行与列值进行比较。



You should only use PWDCOMPARE with a column that was encrypted with PWDENCRYPT.

You should NOT being PWDENCRYPT anymore. Use HASHBYTES instead and compare against the column value yourself.


这篇关于为什么,PWDCOMPARE返回0,应该返回1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆