//验证admin public bool judgeAdmin(string name, string originPass) { bool ret = false; string md5InputStr = MyMd5.getMd5EncryptedStr(originPass); if (con != null) { try { if (con.State != ConnectionState.Open) { con.Open(); } string query = @"select admPass from tabadmins where admName=@name;"; MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = query; cmd.Parameters.AddRange(new MySqlParameter[] { new MySqlParameter("@name", name) }); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { return(ret); } else { string pass = reader.GetString(0); // 取出md5 经过我的encode 后的string pass = PsEnDecode.decode(pass); // 用我的decode 得到md5 string if (pass.Equals(md5InputStr)) //判断数据库得到的md5string 和 输入得到的md5 string { ret = true; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(ret); }
public bool chgAdmPass(string name, string passStr) { bool ret = false; string md5Str = MyMd5.getMd5EncryptedStr(passStr); string encode = PsEnDecode.encode(md5Str); if (con != null) { try { if (con.State != ConnectionState.Open) { con.Open(); } string query = @"update tabadmins set admPass=@pass where admName=@name;"; MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = query; cmd.Parameters.AddWithValue("@pass", encode); cmd.Parameters.AddWithValue("@name", name); try { cmd.ExecuteNonQuery(); ret = true; }catch (Exception ex) { throw new Exception(ex.Message); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(ret); }