Results 1 to 2 of 2

Thread: hashing and comparing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    hashing and comparing

    in few of lines of code,

    1. how can i hash a strPasswd, and

    2. compare it to see if it matches a textbox value
    (when user enters password, it will be compared to the hash in the db)

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

    Re: hashing and comparing

    Try using the following method which uses the MD5 algorithm. You need to reference the System.Security.Cryptography namespace.

    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);
    		}
    Basically pass in a string and it will return the hash in a string format.

    HTH

    DJ

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

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