コード例 #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SendService service  = new SendService();
            string      userName = this.txtUserName.Text.Trim();
            string      password = service.GetMD5(txtPassword.Text.Trim());

            MySqlConnection con       = new MySqlConnection(connectionString);
            string          cmdString = "select * from tb_users where UserName='******' and Password='******'";
            MySqlCommand    cmd       = new MySqlCommand(cmdString, con);

            try
            {
                con.Open();
                MySqlDataReader dr = cmd.ExecuteReader();
                dr.Read();
                if (dr.HasRows)
                {
                    Session["UserName"] = dr.GetValue(1);
                    Response.Redirect("~/CarsManage.aspx");
                }
                else
                {
                    this.lbTips.Text = "账号或密码错误!";
                }
                dr.Close();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
        }
コード例 #2
0
        protected void btnChangePwd_Click(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                this.lbTips.Text = "用户已经登出!";
                return;
            }

            SendService service = new SendService();

            string userName    = this.txtUserName.Text.Trim();
            string oldPassword = service.GetMD5(txtOldPwd.Text.Trim());
            //string newPwd = this.txtNewPwd.Text.Trim();
            string newPwdAgain = service.GetMD5(txtNewPwdAgain.Text.Trim());

            MySqlConnection con       = new MySqlConnection(connectionString);
            string          cmdString = "select * from tb_users where UserName='******' and Password='******'";
            MySqlCommand    cmd       = new MySqlCommand(cmdString, con);

            try
            {
                con.Open();
                MySqlDataReader dr = cmd.ExecuteReader();
                dr.Read();
                if (dr.HasRows)
                {
                    dr.Close();
                    //更新数据库中密码
                    string updateString = "update tb_users set Password='******' where UserName='******'";
                    cmd.CommandText = updateString;
                    cmd.ExecuteNonQuery();
                    this.lbTips.Text = "密码更新成功!";
                }
                else
                {
                    this.lbTips.Text = "账号或密码错误!";
                }
                dr.Close();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
        }