Results 1 to 4 of 4

Thread: hash passwords?

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    hash passwords?

    hi all,

    I need to store user name and password data in a DB for authentication purposes

    I was told that i shouldn't store the pass per say but the hash of the password

    I am very new to this and im not sure what the best way to Proceed is.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: hash passwords?

    When the user creates an account you hash the password, probably salting it too, and then store the hash value in the database. When the user logs in you hash the password they provide and then compare that value to what's in the database.

    To create the hash you would probably use SHA1 or MD5, both of which are supported by the .NET Framework in the System.Security.Cryptography namespace. As for salting:

    http://www.bing.com/search?q=salting+a+hash&form=OSDSRC
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: hash passwords?

    I don't think salting will be necessary this isn't a huge program ( maybe after i get a handle on what im doing)



    so far to hash i use


    c# Code:
    1. private string MD5(string input)
    2.         {
    3.             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    4.  
    5.             byte[] originalBytes = ASCIIEncoding.Default.GetBytes(input);
    6.             byte[] encodedBytes = md5.ComputeHash(originalBytes);
    7.  
    8.             return BitConverter.ToString(encodedBytes).Replace("-", "");
    9.         }


    how would i verify that hash?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: hash passwords?

    You would not use this for a start:
    Code:
    ASCIIEncoding.Default
    Default is a property of the Encoding class that gets a default Encoding object. Either you want a default Encoding or you want an ASCII Encoding. If you want a default encoding then you'd use Encoding.Default. If you want an ASCII Encoding you'd use Encoding.ASCII.

    I'd also be inclined to either use an Encoding in both directions or the BitConverter in both directions. There doesn't seem to be a reason to mix the two.

    Finally, is there a particular reason you're removing dashes from the result? That could conceivably result in the same has for multiple passwords.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width