查询数据库之前把密码md5加密
我在登录的时候在判断密码正确之前先把客户端输入的密码md5加密怎么写?
这是我的登录代码 string sql = "select * from bg_user where username='" + user_name + "'and password='" + password + "'";
        try
        {
            cmd = new MySqlCommand(sql, conn);
            conn.Open();
            MySqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.Read())
            {
                return true;
            }
           else
            {
               return false;
            }
        }

解决方案 »

  1.   

    好像C#有个专门有个加密的exe的运行文件吧
      

  2.   

    /// <summary>
            /// MD5加密
            /// </summary>
            /// <param name="encryptText"></param>
            /// <returns></returns>
            public static string EncryptMD5(string encryptText)
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] encryptBuf = Encoding.ASCII.GetBytes(encryptText);
                encryptBuf = md5.ComputeHash(encryptBuf);
                return Convert.ToBase64String(encryptBuf);
            }
      

  3.   

     public static string MD5(string str)
            {
                byte[] result = Encoding.Default.GetBytes(str.Trim());  
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] output = md5.ComputeHash(result);
                return BitConverter.ToString(output).Replace("-", "");        }
      

  4.   


     string user_name = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text, "MD5"); //TextBox1.Text为密码框的值
            string sql = "select * from bg_user where username='" + user_name + "'and password='" + password + "'";
      

  5.   

         MD5算法一致,所以只需要在登录代码中把密码用MD5加密一次,然后与数据库中的作对比,是这样实现登录的。。
    string sql = "select * from bg_user where username='" + user_name + "'and password='" + MD5(password) + "'";
     
      

  6.   

    //我用的也是如楼上一样
    string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.ToString().Replace(" ", ""), "MD5").ToString();//密码加密
      

  7.   

    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text, "MD5"); 这个就够用了