locked
MySqlDataReader with MD5 RRS feed

  • Question

  • User629360359 posted

    I encrypted my password with MD5, but now i having the problem while i need to decrypt it by using MySqlDataReader.

    cmd.CommandText = "SELECT * FROM member WHERE loginID = '" + this.txtID.Text + "'";
    conn.open();
    MySql.Data.MySqlClient.MySqlDataReader dr = cmd.ExecuteReader();
    if(dr.Read())
    {
       if(this.txtPassword.Text == dr["password"].ToString())
       {
          Response.Write("Succuess");
       }
       else
       {
          Response.Write("failed");
       }
    } 


    for some reason, i need to put my "password" under DataReader, please advice

    Sunday, December 2, 2012 7:58 PM

Answers

  • User629360359 posted
    public string CalculateMD5Hash(string input)
    {
        // step 1, calculate MD5 hash from input
        MD5 md5 = System.Security.Cryptography.MD5.Create();
        byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
        byte[] hash = md5.ComputeHash(inputBytes);
     
        // step 2, convert byte array to hex string
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hash.Length; i++)
        {
            sb.Append(hash[i].ToString("X2"));
        }
        return sb.ToString();
    }

    http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 1:00 AM