Results 1 to 9 of 9

Thread: Need Some Help With SHA-1 HASH

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    2

    Need Some Help With SHA-1 HASH

    I really hope someone could help me out with this...I have an SQL database for my server that contains usernames and passwords for all my clients. When people create their accounts on my website (CMS), their passwords are encrypted in SHA-1 Hash form...

    Now, I'm making a program that requires authentication. So basically the person is supposed to enter their information (username and password) that is stored in the SQL database to be able to access the program. I am using THIS tutorial to teach me how to do this: http://www.youtube.com/watch?v=u1waZnO8PCk

    One problem, since the passwords are stored in SHA-1 I can't think of a way to make it read the SHA-1 passwords that are stored in the DB, when the person enters a string type piece of text as their password while they try to login.

    Could anyone help me out? Thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Need Some Help With SHA-1 HASH


  3. #3
    New Member
    Join Date
    Jul 12
    Posts
    2

    Re: Need Some Help With SHA-1 HASH

    Could you please provide a little assistance with this?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,805

    Re: Need Some Help With SHA-1 HASH

    First of all, the passwords are not encrypted. They are hashed. Encryption is a two-way process while hashing is one-way.

    Therein lies the problem with your thinking. You seem to be under the impression that you're supposed to get the hashed password from the database, decrypt it and then compare the result to the password the user typed in. That is not the case. The whole point of hashing is that basically you cannot recreate the original data from the hash. That's why it's secure.

    When the user registers, you are hashing the password they provide and storing the result in the database. When a user logs in, you use the user name, if such a user name exists, to get the hash from the database. You then hash the password they logged in with and then compare the two hashes. If the hashes are the same then the original passwords are the same too, so the user is authenticated.

  5. #5
    Addicted Member
    Join Date
    Nov 11
    Posts
    174

    Re: Need Some Help With SHA-1 HASH

    jmcilhinney,

    do you approve of dunfiddlin's solution? coz i wanna use it

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,805

    Re: Need Some Help With SHA-1 HASH

    Quote Originally Posted by m.davide View Post
    jmcilhinney,

    do you approve of dunfiddlin's solution? coz i wanna use it
    There's not much to generating the hash so that's fine. I probably would have used SHA1Managed rather than SHA1CryptoServiceProvider but that's no big deal. Also, I would probably have used Convert.ToBase64String to create a base64 representation of the Byte array rather than converting each Byte to hexadecimal. Again, that's not really a big deal.

    That still doesn't tell you how to use the hash though, which I think is the issue the OP was having. See my previous post for that.

  7. #7
    Addicted Member
    Join Date
    Nov 11
    Posts
    174

    Re: Need Some Help With SHA-1 HASH

    What I did is just store my hashed password on a varchar attribute. Then when a user logs in, I just retrieve the hashed password and compare it to the Text on the password field/TextBox with a simple If-else statement.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,805

    Re: Need Some Help With SHA-1 HASH

    Quote Originally Posted by m.davide View Post
    What I did is just store my hashed password on a varchar attribute. Then when a user logs in, I just retrieve the hashed password and compare it to the Text on the password field/TextBox with a simple If-else statement.
    That's all correct except that, as I posted earlier, you need to hash the password provided at login and compare that to the hash created from the password provided at registration. I'm guessing that you're actually doing that already but just neglected to mention it specifically.

  9. #9
    Addicted Member
    Join Date
    Nov 11
    Posts
    174

    Re: Need Some Help With SHA-1 HASH

    Yeah, I totally forgot to mention it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •