Results 1 to 3 of 3

Thread: Hashing Passwords

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Hashing Passwords

    Hi

    I'm using the following C# code to hash a password before it is stored in a database.

    Code:
    	public static string Encrypt(string cleanString)
    		{
    		Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
    		Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
    
    		return BitConverter.ToString(hashedBytes);
    	}
    When someone logs in I hash the password entered and compare against the stored hashed password.

    Now this seems to work in most cases but every so often the hashed passwords don't match!

    Just wondering if there is a salt or anything similar that might be setup somewhere e.g. machine.config.

    This is all on a shared server so it is possible the host is changing something somewhere that I don't know about.

    Help!

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Hashing Passwords

    The code seems right to me. One thing though, are you using that with ASP.Net? If so, could the posted password change of a user change depending on OS default locale and browser settings?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3
    Lively Member
    Join Date
    May 2004
    Posts
    104

    Re: Hashing Passwords

    I dont have the locale problem. I have had the problem where some characters would just not work. They were considered escape characters in SQL server so it would not write the hash as a string. This happened to me when a person entered a password that started with a h. All I knew is that a hash was generated and it was consistent everytime however, it generated an escape sequence the first three characters or so. Luck of the draw I suppose. A hash should never use different hashes for the same value. Even with using MD5 to hash. Message Digest v 5 should have enough juice to not have to rehash same passwords over again. Try around 20 different passwords and see what you get when you repeat them. Post the number of times the passwords came out the same and the number of times it came out different. What I might could tell you is that you might be like me and figure out that you are using some illegal sequence somewhere. And then tell your users not to have a password that starts with a h lol.

    Pol

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