Beispiel #1
0
        protected void surebtm_Click(object sender, EventArgs e)
        {
            string name = Request["username"];
            string password = Request["password"];
            PersonEntity person = new PersonEntity();
            person.Password = password;
            person.Username = name;
            Didsqlconntion sql = new Didsqlconntion();
            if (name == "")
            {
                userLab.Text = "用户名不能为空!";
            }

                if (sql.getperson(person))
                {

                    // Response.Cookies.Add(cookie);
                    if (menberbox.Checked)
                    {
                        HttpCookie cookie = new HttpCookie("user", name);
                        cookie.Expires = DateTime.MaxValue;//设置Cookie 永不过期
                        Response.Cookies.Add(cookie);

                    }
                    Server.Transfer("Main.aspx");
                }
                else
                {
                    errorLab.Text = "用户名或密码错误!";

                }
        }
Beispiel #2
0
        public bool getperson(PersonEntity person)
        {
            bool flag = false;
            conn.Open();
            string query = "select * from persondetails where username=?name and password=?password";
            MySqlCommand myCommand = new MySqlCommand(query, conn);
            myCommand.Parameters.AddWithValue("?name", person.Username);
            myCommand.Parameters.AddWithValue("?password", person.Password);

            myCommand.ExecuteNonQuery();
            MySqlDataReader myDataReader = myCommand.ExecuteReader();
            while (myDataReader.Read() == true)
            {
                personentity.Username = myDataReader["username"].ToString().Trim();
                personentity.Password = myDataReader["password"].ToString().Trim();
            }
            if (person.Username.Equals(personentity.Username)&&person.Password.Equals(personentity.Password))
            {
                flag =true ;
            }
            conn.Close();
            myDataReader.Close();
            return flag;
        }