MD5 HashByte  .NET , SQL

joschramm
joschramm used Ask the Experts™
on
Hi All,

i am Developing a web Project with a login site and i need to Convert my Password in an MD5 HashCode, the password is in my MSSQL DATABASE in an "master.dbo.fn_varbintohexstr(HashBytes('MD5',Password))"  Converted.
and in my .Net VisualStudio i retrieve this Password and compare it with the Logins Password Texfield wich i Converted in MD5 before i compare . my Problem is that the Hashcode in SQL is different that the hashcode in .NET althought i write the same Password. can anyone tell why and how i solved my Problem.
thanks in advanced..
//here is the Method wich i Convert the Textfiel Password in MD5 .NET     
 
   public static string GetMD5Hash(string TextToHash)
        {
            //Prüfen ob Daten übergeben wurden.
            if (string.IsNullOrEmpty(TextToHash))
            {
                return string.Empty;
            }
            MD5 md5 = new MD5CryptoServiceProvider();
            UTF8Encoding encoder = new UTF8Encoding();
            byte[] textToHash = encoder.GetBytes(TextToHash);
            byte[] result = md5.ComputeHash(textToHash);
            return BitConverter.ToString(result);
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
hi, i found the solution.
my Password from the Database give me an HashByte with '0x' in the beginning of the code and in my .Net give me without it, thats why it wasnt equal.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial