Note that there are some explanatory texts on larger screens.

plurals
  1. POhash and compare password which is saved as hash using SHA1 in sql server
    primarykey
    data
    text
    <p>i have a column of varbinary(max) type and used a salt of nvarchar(60) type that is generated randomly. I saved the salt in db and saved password using hashbyte(password+ salt).</p> <p>Now I want to compare user password and authenticate him.</p> <p>I tried taking his password and running this query--</p> <pre><code>SELECT [email] from admin where [password]=HashBytes('SHA1','xxxxxx' +'/KsDnXdU+_a&lt;t19wYCnEi/lxmXmAutR3DVA$#]~dSBskRMB?sb#41+=MFRpE') </code></pre> <p>It is not returning me email. I ran it directly on sql server management studio. But It gave me blank. Why is it so?</p> <p>When im selecting by email im getting role, this means email is registered. Is something wrong in my salt or query?</p> <p>I fixed it. Actualy adding salt directly was causing me a bug, though it was getting added directly and hash was computed and no error was returned from sql server.</p> <p>When i ran this query </p> <pre><code>Select role from admin where salt='/KsDnXdU+_a&lt;t19wYCnEi/lxmXmAutR3DVA$#]~dSBskRMB?sb#41+=MFRpE' </code></pre> <p>I got no result. I realised, it was some Conversion problem. I used then <code>Convert(nvarchar(60),'%?r&gt;%Vb+$hUZO8}=38/_J[@q@1mf^rz!V&amp;q~\dLH5nQ&amp;/edR\c[6ya|q$e%r')</code> </p> <p>and ran my query as </p> <pre><code>SELECT [email] from admin where [password]=HashBytes('SHA1', 'xxxxxx'+Convert(nvarchar(60),'%?r&gt;%Vb+$hUZO8}=38/_J[@q@1mf^rz!V&amp;q~\dLH5nQ&amp;/edR\c[6ya|q$e%r')) </code></pre> <p>This returned me email. I am really not sure why this happened, but using sqlserver 2005, and above query i fixed it. I request moderators, If it is any bug in sql server 2005, please do let other know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload