62,254
社区成员
发帖
与我相关
我的任务
分享
public class SQLEDIT : CommonPageBase
{
public string AlertScript = string.Empty;
private string checkcode;
public string msg = string.Empty;
private string name;
public bool CheckName(string name)
{
string commandText = "select count(0) from [test] where id=@id";
SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@id", SqlDbType.VarChar, 0x15) };
commandParameters[0].Value = name;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
}
public bool CheckPass(string name, string pass)
{
string commandText = "select count(0) from [test] where id=@id and pass=@pass";
SqlParameter[] commandParameters = new SqlParameter[2];
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
commandParameters[0] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[0].Value = name;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
int num = (int) sqlconnet.ExecuteScalar(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters);
return (num > 0);
}
protected void Page_Load(object sender, EventArgs e)
{
if (base.IsHttpPost)
{
bool flag = true;
this.checkcode = base.Request.Form["txtCode"].ToString();
if (!bmptool.CheckName(base.Request.Form["txtName"]))
{
this.AlertScript = "AlertScript('div_name','用户名格式错误');";
flag = false;
}
else
{
this.name = base.Request.Form["txtName"].ToString();
}
if (!(this.CheckName(base.Request.Form["txtName"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_name','用户名不存在');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtoldPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码格式错误');";
flag = false;
}
if (!(bmptool.CheckPassword(base.Request.Form["txtnewPwd"]) || !flag))
{
this.AlertScript = "AlertScript('div_pwdc','新密码格式错误');";
flag = false;
}
if ((base.Request.Form["txtnewPwd"].ToString() != base.Request.Form["txtnewPwdc"].ToString()) && flag)
{
this.AlertScript = "AlertScript('div_newpwdc','新密码输入不一致');";
flag = false;
}
if (!(this.CheckPass(base.Request.Form["txtName"].ToString(), base.Request.Form["txtoldPwd"].ToString()) || !flag))
{
this.AlertScript = "AlertScript('div_pwd','旧密码与原密码不匹配!');";
flag = false;
}
if ((this.checkcode != base.Request.Cookies["bmpcode"].Value.ToString()) && flag)
{
this.AlertScript = "AlertScript('div_code','验证码错误');";
flag = false;
}
if (flag)
{
if (this.edits(this.name, base.Request.Form["txtnewPwd"].ToString()))
{
this.msg = "RegMsg('密码修改成功!<br>用户名是:" + this.name + "。<br>新密码是:" + base.Request.Form["txtnewPwd"].ToString() + "<br><div class=\"btnp\"><input name=\"btnClose\" value=\"关闭\" type=\"button\" onclick=\"new window.top.Box().Close();\" /></div>');";
}
else
{
this.msg = "RegMsg('修改失败!稍后再修改...<br>关闭窗口');";
}
}
}
}
public bool edits(string name, string pass)
{
string commandText = "update [test] set password=@password,pass=@pass where id=@id";
string str2 = MD5.HashString(pass, Encoding.GetEncoding("GB2312"));
SqlParameter[] commandParameters = new SqlParameter[3];
commandParameters[0] = new SqlParameter("@password", SqlDbType.VarChar, 0x24);
commandParameters[0].Value = pass;
commandParameters[1] = new SqlParameter("@pass", SqlDbType.VarChar, 0x24);
commandParameters[1].Value = str2;
commandParameters[2] = new SqlParameter("@id", SqlDbType.VarChar, 0x15);
commandParameters[2].Value = name;
return (sqlconnet.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["test"].ConnectionString, CommandType.Text, commandText, commandParameters) > 0);
}
}
}