private void button2_Click(object sender, EventArgs e) { String password = this.textBox3.Text.Trim(); String jm = MD5Encrypt64.MD5Encrypt(password); try { String sql = "update users set password = '******' where user = '******'"; MySqlDataReader dr = Database.Dr(sql); //执行语句 if (dr.Read()) //如果dr读到了信息返回true;否则返回false { MessageBox.Show("检测的姿势不对,请换个姿势"); } else { MessageBox.Show("修改成功"); login login = new login(); this.Hide(); login.Show(); } } catch { MessageBox.Show("连接数据库的姿势不对"); Database.Close(); } Database.Close(); }
private void button1_Click(object sender, EventArgs e) { //Database conn = new Database(); //MD5Encrypt64 md5 = new MD5Encrypt64(); //新建数据库对象 // conn.sqlcmd.Connection = conn.conn;//设置数据库连接 //MySqlDataReader dr = sqlcmd.ExecuteReader(); //bool str = dr.Read(); String password = this.textBox2.Text.Trim(); String jm = MD5Encrypt64.MD5Encrypt(password); //md5 加密 try { // MySqlCommand mycom = conn.CreateCommand(); //利用现有连接创建一个Command,用以执行sql指令 // conn.conn.Open(); // conn.sqlcmd.CommandText = "select id,user,password,role from users where user='******'"; // MySqlDataReader dr = conn.sqlcmd.ExecuteReader(); //执行语句 String sql = "select id,user,password,role from users where user='******'"; MySqlDataReader dr = Database.Dr(sql); if (dr.Read()) //如果dr读到了信息返回true;否则返回false { if (dr["password"].ToString() == jm) { Form1.th = dr["user"].ToString(); Form1.id = (int)dr["id"]; Form1.role = dr["role"].ToString(); MessageBox.Show("登录成功!"); Form1 log = new Form1(); this.Hide(); log.Show(); } else { MessageBox.Show("登录的姿势不对,请换个姿势2"); } } else { MessageBox.Show("登录的姿势不对,请换个姿势"); } } catch { MessageBox.Show("连接数据库的姿势不对"); Database.Close(); } Database.Close(); //String name = this.textBox1.Text; // 获取里面的值 //String password = this.textBox2.Text; //if (name.Equals("admin") && password.Equals("yszm")) // 判断账号密码 //{ // MessageBox.Show("登录成功"); // // this.Hide(); // //log.Show(); // this.DialogResult = DialogResult.OK; // this.Close(); //} //else //{ // MessageBox.Show("登录失败!"); //} }