Пример #1
0
 protected void Logon_Click(object sender, EventArgs e)
 {
     if ((txtUserName.Text == "" || txtPassword.Text == "" || txtQpassword.Text == "" || txtQQ.Text == "") || (male.Checked == false && famale.Checked == false) || txtPassword.Text != txtQpassword.Text)
     {
         Response.Write("<script>alert('注册失败,请正确填写信息!')</script>");
     }
     else
     {
         if (isName())
         {
             Response.Write("<script>alert('注册失败,该用户名已被注册!')</script>");
         }
         else
         {
             string   userName = txtUserName.Text;
             MD5Class md5      = new MD5Class();
             string   userPass = md5.Md5Encrypt(txtPassword.Text);
             string   qq       = txtQQ.Text;
             string   sex      = "";
             if (male.Checked == true)
             {
                 sex = "male";
             }
             else if (famale.Checked == true)
             {
                 sex = "famale";
             }
             string    mysqlinsert = "insert into tb_user(Uid,PassWord,QQ,Sex) values('" + userName + "','" + userPass + "','" + qq + "','" + sex + "')";
             MySqlData da          = new MySqlData();
             bool      add         = da.ExceSQL(mysqlinsert);
             if (add == true)
             {
                 Response.Write("<script>alert('注册成功!')</script>");
                 txtPassword.Text = txtQpassword.Text = txtUserName.Text = txtQQ.Text = "";
             }
             else
             {
                 Response.Write("<script>alert('注册失败!')</script>");
             }
         }
     }
 }
Пример #2
0
        protected void Login_Click(object sender, EventArgs e)
        {
            string code = txtCode.Text;

            if (Request.Cookies["CheckCode"].Value == code)
            {
                MySqlConnection con = new MySqlConnection("server=localhost;database=messageboard;User id=root;password=095637");
                con.Open();
                MD5Class     md5      = new MD5Class();
                string       pass     = md5.Md5Encrypt(txtPassword.Text);
                string       mysqlSel = "select *from tb_user where Uid=@username and PassWord=@userpass";
                MySqlCommand com      = new MySqlCommand(mysqlSel, con);
                com.CommandType = System.Data.CommandType.Text;
                com.Parameters.Add(new MySqlParameter("username", MySqlDbType.VarChar, 20));
                com.Parameters["username"].Value = txtUserName.Text;
                com.Parameters.Add(new MySqlParameter("userpass", MySqlDbType.VarChar, 100));
                com.Parameters["userpass"].Value = pass;

                if (Convert.ToInt32(com.ExecuteScalar()) > 0)
                {
                    MySqlDataReader myDr = com.ExecuteReader();
                    myDr.Read();
                    Session["userName"] = txtUserName.Text;
                    Response.Redirect("ShowSubject.aspx?userID='" + myDr["ID"] + "'");
                    txtCode.Text = "";
                    myDr.Close();
                }
                else
                {
                    Warning.Text = "用户名或密码错误";
                }
                con.Close();
            }
            else
            {
                Warning.Text = "验证码输入错误";
            }
        }