protected void btnPwdSet_Click(object sender, EventArgs e) { string number = txtNumber.Text; if (number == null || number == "") { Response.Write("<script> alert('请输入账号!');</script> "); txtPwdSet.Text = null; txtPwdSure.Text = null; } else { SQLOperation sqlOperate = new SQLOperation(); if (Session["checkCode"] == null) { Response.Write("<script> alert('请先获得验证码!');</script> "); } else if (txtCode.Text != Session["checkCode"].ToString()) { if (txtCode.Text == null || txtCode.Text == "") { Response.Write("<script> alert('请输入六位验证码!');</script> "); } else { Response.Write("<script> alert('验证码错误!');</script> "); txtNumber = null; txtPwdSet = null; txtPwdSure = null; } } else { if (txtPwdSet.Text != txtPwdSure.Text) { Response.Write("<script> alert('新密码不一致!');</script> "); txtPwdSet.Text = null; txtPwdSure.Text = null; } else if (txtPwdSet.Text == "" || txtPwdSet.Text == null) { Response.Write("<script> alert('密码不能为空!');</script> "); } else { SpecialOperations op = new SpecialOperations(); string pwd = op.MD5String(txtPwdSet.Text); sqlOperate.update(" users ", " password = '******'", " number='" + number + "'"); Response.Write("<script> alert('密码已修改,请重新登录!');location='MainPage.aspx'</script> "); Session["checkCode"] = null; } } } }
protected void btnLogin_Click(object sender, EventArgs e) { SpecialOperations operate = new SpecialOperations(); string number = txtNumber.Text; string pwd = operate.MD5String(txtPwd.Text); //md5加密 //SELECT 列名称 FROM 表名称 WHERE 列 运算符 值 string getPwd; SQLOperation sqlOperate = new SQLOperation(); DataTable dt = new DataTable(); dt = sqlOperate.select(" password,id ", " Users ", " number='" + number + "'"); if (dt.Rows.Count == 0) { Response.Write("<script> alert('账号不存在');</script> "); //if the database doesn't hava a line,can't find the user } else if ((getPwd = dt.Rows[0][0].ToString().Trim()) != pwd) { Response.Write("<script> alert('密码错误!');</script> "); txtPwd.Text = null; } else if ((getPwd = dt.Rows[0][0].ToString().Trim()) == pwd) { Session["NowUserId"] = dt.Rows[0][1].ToString().Trim(); dt = sqlOperate.select(" loginStatus ", " users ", " id =" + Session["NowUserId"].ToString()); string status = dt.Rows[0][0].ToString().Trim(); if (status == "下线") { sqlOperate.update(" users ", " loginstatus='在线' ", " id=" + Session["NowUserId"].ToString()); //change online status /* if(btnRememberPwd.Checked == true) * { * CookieOperation c*k = new CookieOperation(); * c*k.addUser(number, pwd); * }*/ Response.Write("<script> alert('登陆成功!');location= 'PersonalCenterPage.aspx'</script> "); } else { Response.Write("<script> alert('当前用户已经在线!');location= 'PersonalCenterPage.aspx'</script> "); } } }
protected void btnRegister_Click(object sender, EventArgs e) { SpecialOperations operate = new SpecialOperations(); string number = operate.generateRandomNum(10); string sex; if (btnMan.Checked) { sex = btnMan.Text; } else if (btnWoman.Checked) { sex = btnWoman.Text; } else { sex = null; } string checkCode = Session["checkCode"].ToString(); bool emptyJudge = operate.nullString(txtName.Text) || operate.nullString(sex) || operate.nullString(txtEmail.Text) || operate.nullString(txtCode.Text) || operate.nullString(txtPwdSet.Text) || operate.nullString(txtPwdSure.Text); bool overLengthJudge = operate.overLength(txtName.Text, 20) || operate.overLength(txtEmail.Text, 20) || operate.overLength(txtCode.Text, 6) || operate.overLength(txtPwdSet.Text, 10); if (emptyJudge) { Response.Write("<script> alert('有内容尚未完成!');</script> "); } else if (overLengthJudge) { Response.Write("<script> alert('有内容超出限定长度!');</script> "); } else if (operate.not_equal(txtPwdSet.Text, txtPwdSure.Text)) { Response.Write("<script> alert('两次输入的密码不一致');</script> "); } else if (operate.not_equal(checkCode, txtCode.Text)) { Response.Write("<script> alert('验证码错误');</script> "); } else { SQLOperation sql = new SQLOperation(); // sql = new SQLOperation(); string nickname = txtName.Text; string password = operate.MD5String(txtPwdSet.Text); string loginstatus = "下线"; string email = txtEmail.Text; //' nickname ','number','password','loginstatus','name','sex','age','headpicture','email','birthday' string values = "N'" + nickname + "', " + "N'" + number + "','" + password + "',N'" + loginstatus + "','" + null + "',N'" + sex + "','" + null + "',' ~\\images\\default.png ','" + email + "','" + null + "'"; if (sql.add(" users ", values)) { DataTable dt = sql.select(" id ", " users ", " number = '" + number + "'"); string id = dt.Rows[0][0].ToString(); string zoneDefultValue = id + ",N'" + nickname + "的空间'"; //give a default name for zone //userid,name,classkind,amount sql.add(" classes ", " " + id + " ,'所有日志','日志',0,'F'"); //注册就得到一个存放所有日志的默认分类 sql.add(" a_album ", " " + id + ",'所有照片',0,null,null,'F'"); //注册的到一个默认相册 if (sql.add(" zoneInfo ", zoneDefultValue)) { Response.Write("<script> alert('注册成功你的账号是" + number + "');location= 'MainPage.aspx'</script> "); } } else { Response.Write("<script> alert('注册失败');</script>"); } /*全部清空*/ txtEmail.Text = null; txtCode.Text = null; txtPwdSet.Text = null; txtPwdSure.Text = null; txtName.Text = null; } }