MD5 HashByte  .NET , SQL

Posted on 2008-11-10
Last Modified: 2013-12-17
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

Question by:joschramm
    1 Comment

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now