日期:2014-05-18 浏览次数:20745 次
namespace Pmis.Web
{
using System;
using System.Text;
using System.Data;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
public class ChgPwd : Page
{
public TextBox tbxPwd1;
public TextBox tbxPwd2;
public TextBox tbxPwd3;
public Label lblA1;
public void Page_Load()
{
if (Session["LoginOK"] == null || (bool)Session["LoginOK"] != true)
{
Response.Redirect("login.aspx");
}
}
public void SubmitBtn_Click(Object Sender, EventArgs e)
{
if (tbxPwd1.Text.Length == 0 || tbxPwd2.Text.Length == 0 || tbxPwd3.Text.Length == 0
|| tbxPwd2.Text != tbxPwd3.Text)
{
lblA1.Text = "输入不正确";
return;
}
if (tbxPwd1.Text == tbxPwd2.Text)
{
lblA1.Text = "新密码不得与旧密码相同";
return;
}
string sql = "update [staff] set [pwd]=@pwd2,[mustchangepwd]=0 where [coid]=@coid and [pwd]=@pwd1";
SqlParameter para1 = new SqlParameter("@coid", SqlDbType.Int);
para1.Value = (int)Session["StaffCoid"];
SqlParameter para2 = new SqlParameter("@pwd1", SqlDbType.Binary);
para2.Value = (new MD5CryptoServiceProvider()).ComputeHash(Encoding.UTF8.GetBytes(tbxPwd1.Text));
SqlParameter para3 = new SqlParameter("@pwd2", SqlDbType.Binary);
para3.Value = (new MD5CryptoServiceProvider()).ComputeHash(Encoding.UTF8.GetBytes(tbxPwd2.Text));
int n = (new SqlQuery()).ExecNonQuery(sql, para1, para2, para3);
lblA1.Text = (n > 0) ? "密码修改成功" : "密码修改失败,可能是输入的旧密码不正确";
}
}
}