简体   繁体   English

SQL Server:如何在存储过程中创建HashPassword

[英]SQL Server: How to create HashPassword In Stored Procedure

Hey so at the moment in my table I have a column called 嘿,目前我的表格中有一列叫做

"hash" and "salt" “哈希”和“盐”

hash is my Hashpassword of the user entered string and salt 哈希是我输入的字符串和盐的用户的哈希密码

and salt is the single salt value 盐是单一盐值

During user login rather than retreive the salt from DB, create the hashpasword in my code and then compare with hash in DB I am told I can do this straight in my stored procedure. 在用户登录期间,而不是从数据库中检索盐,请在我的代码中创建hashpasword,然后与DB中的哈希进行比较,我被告知我可以直接在存储过程中执行此操作。

This is my stored procedure at the moment 这是我目前的存储过程

ALTER PROCEDURE [dbo].[spCheckMemberLogin]
(
    @username VARCHAR(100) = default,
    @hash VARCHAR(100) = default
)
AS
BEGIN

    SET NOCOUNT ON;

    SELECT
         3 as result
    ,    * 
    FROM
        web_user 
    WHERE 
        (statusId = 1) 
        AND (useremail = @username) 
        AND (hash = @hash)

END

Instead of having hash = @hash 而不是使用hash = @hash

How can I have 我怎么有

hash = HashBytes('SHA1', salt+user entered password) hash = HashBytes('SHA1',salt +用户输入的密码)

where salt should be retrieve from table and user entered password is a variable of the stored procedure 应该从表中检索盐,并且用户输入的密码是存储过程的变量

It depends on your version of SQL server. 这取决于您的SQL Server版本。 Anything equal or superior to 2005 will have the HashBytes procedure: 等于或优于2005的任何事物都将具有HashBytes过程:

http://msdn.microsoft.com/en-us/library/ms174415.aspx http://msdn.microsoft.com/en-us/library/ms174415.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM