Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MS SQL哈希密码与纯文本密码的比较_Java_Sql Server_Database_Encryption_Hash - Fatal编程技术网

Java MS SQL哈希密码与纯文本密码的比较

Java MS SQL哈希密码与纯文本密码的比较,java,sql-server,database,encryption,hash,Java,Sql Server,Database,Encryption,Hash,我想知道我怎样才能让我的小程序运行起来。我所需要的只是当我输入我的密码时,密码是Password321为了与MS SQL数据库中password列下的哈希密码进行比较,我尝试使用PWDCOMPARE('Password321!',password)但它对我不起作用。将nvarchar值“nEg5JzRQHD8P7VOwwIkeaDx6WEs=”转换为数据类型int时,出现一个错误,表示转换失败。 这是我的密码: select Password from aspnet_Membership whe

我想知道我怎样才能让我的小程序运行起来。我所需要的只是当我输入我的密码时,密码是Password321为了与MS SQL数据库中
password
列下的哈希密码进行比较,我尝试使用
PWDCOMPARE('Password321!',password)但它对我不起作用。将nvarchar值“nEg5JzRQHD8P7VOwwIkeaDx6WEs=”转换为数据类型int时,出现一个错误,表示转换失败。
这是我的密码:

select Password from aspnet_Membership where Password=PWDCOMPARE('Password321!', Password);
请帮忙

谢谢


M

如果您使用SQL server对用户进行身份验证,则应尝试利用最佳做法,将SQL注入web服务器的可能性降至最低

下面的查询是使用SHA1身份验证对登录用户进行身份验证的一个很好的示例。 注意,它不是一个java实现,但它应该能让您很好地了解自己做错了什么

sql = "SELECT user_id, user_name, user_level 
        FROM users
        WHERE user_name = '" . mysql_real_escape_string($_POST['user_name']) . "'
        AND user_pass = '" . sha1($_POST['user_pass']) . "'";

对于
SQL Server
PWDCOMPARE()
返回int值
1
,前提是给定的密码mataces else返回
0

Hashes a password and compares the hash to the hash of an existing password. 
语法:

PWDCOMPARE ( 'clear_text_password', password_hash [ , version ] )
    Returns the SQL Server password hash of the input value that uses the current 
version of the password hashing algorithm.
PWDENCRYPT ( 'password' )
如果明文密码的散列与密码散列参数匹配,则返回1;如果不匹配,则返回0

像这样更改您的查询

SELECT Password 
FROM aspnet_Membership 
WHERE PWDCOMPARE('Password321!', Password) = 1;
SELECT Password 
FROM aspnet_Membership 
WHERE Password = PWDENCRYPT('Password321!');
或者您可以使用PWDENCRYPT()

PWDCOMPARE ( 'clear_text_password', password_hash [ , version ] )
    Returns the SQL Server password hash of the input value that uses the current 
version of the password hashing algorithm.
PWDENCRYPT ( 'password' )
语法:

PWDCOMPARE ( 'clear_text_password', password_hash [ , version ] )
    Returns the SQL Server password hash of the input value that uses the current 
version of the password hashing algorithm.
PWDENCRYPT ( 'password' )
像这样更改您的查询

SELECT Password 
FROM aspnet_Membership 
WHERE PWDCOMPARE('Password321!', Password) = 1;
SELECT Password 
FROM aspnet_Membership 
WHERE Password = PWDENCRYPT('Password321!');

只有当您知道密码\u散列时,才能使用PWDCOMPARE('Password321!',Password)。因为PWDCOMPARE将文本\u格式密码与密码\u散列进行比较。i、 例如“选择SL.name,PWDCOMPARE('*********',SL.password_hash)password_match FROM sys.sql_登录为SL,其中SL.name='ALogin';”链接到相关文档(为了显示您是如何知道答案是什么的)将使这成为一个更好的答案;输出结果为零,但如果您输入0,则我尝试的下一个数据是:选择密码,PWDCOMPARE('Password321!',Password)Password_匹配来自aspnet_成员,其中UserName='admin'的aspnet_用户;密码匹配=0;我使用了Prakar Asthana的示例,用于sa,返回1。我所做的就是,使用asp.net的成员身份,使用aspnet_regsql.exe,然后使用asp.net工具箱中的CreateUserWizard,创建一个密码不匹配的帐户。感谢回复,我刚刚从我的网站删除了MD5哈希,现在使用SHA-256,这对我来说会更好。正如我在互联网上看到的,SHA1将于2016年或2017年停产。此外,我将尝试使用表单执行sql语句,以减少MS sql上sql注入的问题。