title: SQL Server: How to create HashPassword In Stored Procedure
body: <p>Hey so at the moment in my table I have a column called</p>
  
  <p>"hash"
  and 
  "salt"</p>
  
  <p>hash is my Hashpassword of the user entered string and salt</p>
  
  <p>and salt is the single salt value</p>
  
  <p>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.</p>
  
  <p>This is my stored procedure at the moment</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Instead of having
  hash = @hash</p>
  
  <p>How can I have</p>
  
  <p>hash = HashBytes('SHA1', salt+user entered password)</p>
  
  <p>where salt should be retrieve from table and user entered password is a variable of the stored procedure</p>