asp.net系统增加用户登录后修改密码的功能

[size=xx-large][size=large]1、增加用户登录后修改密码的功能
a)前台添加控件
</script>
<style type="text/css">
/*按钮的样式*/
.savebnt
{
font-size:14px;
color:#3366CC;
font-weight:bold;
cursor:pointer;
border:#3366CC 2px solid;
background:#CCCCFF;


}
</style>
<table width="90%" border="0" align="center" cellspacing="0">
<tr>
<td colspan="5" align="left" style="border-bottom:1px solid #3366CC; color:Red">&nbsp;<b><font size="3">用户基本信息</font></b></td>
</tr>
<tr>
<td height="30" align="right" class="style1">用户姓名:</td>
<td height="30" class="style3">
<asp:Label ID="lb_userName" runat="server" Text="Label"></asp:Label></td>
<td height="30" align="right" class="style1">旧密码:</td>
<td height="30" class="style2">
<asp:TextBox ID="oldpass" runat="server" MaxLength="20" Width="150" TextMode="Password"></asp:TextBox>
</td>
<td rowspan="3" style="border-bottom:1px solid #3366CC">
<asp:Button ID="savePass" runat="server" Text="点击修改密码" Height="60" Width="120"
CssClass="savebnt" οnclick="savePass_Click"/>
<asp:Label ID="lb_msg" runat="server" Text="" ForeColor="red"></asp:Label>

</td>
</tr>
<tr>
<td height="30" align="right" class="style1">用户类型:</td>
<td height="30" class="style3"><asp:Label ID="lb_userType" runat="server" Text="Label"></asp:Label></td>
<td height="30" align="right" class="style1">新密码:</td>
<td height="30" class="style2">
<asp:TextBox ID="newpass" runat="server" MaxLength="20" Width="150" TextMode="Password"></asp:TextBox>
(5-20位)
</td>
</tr>
<tr >
<td height="30" align="right" style="border-bottom:1px solid #3366CC"
class="style1">测评阶段:</td>
<td height="30" style="border-bottom:1px solid #3366CC" class="style3">
<asp:Label ID="lb_section" runat="server" Text="Label"></asp:Label></td>
<td height="30" align="right" class="style1" style="border-bottom:1px solid #3366CC">确认新密码:</td>
<td height="30" style="border-bottom:1px solid #3366CC" class="style2">
<asp:TextBox ID="newpass2" runat="server" MaxLength="20" Width="150" TextMode="Password"></asp:TextBox>
</td>
</tr>
</table>


b)后台添加代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
public partial class files_user_info : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Security.checkLogin();
this.lb_section.Text = SectionManager.getSectionName();
this.lb_userName.Text = Session["userName"].ToString();


if ("system".Equals(Session["userType"].ToString()))
{
this.lb_userType.Text = "系统管理员";
}
if ("user".Equals(Session["userType"].ToString()))
{
this.lb_userType.Text = "普通用户";
}

if (!this.IsPostBack) {
messageBind();
checkSZ();
}

}

public void messageBind() {
String sql = "select * from [发布信息表] where [状态]=1 order by [排序] desc,[时间] desc";
DataSet ds = DbHelperOleDb.Query(sql);
this.ItemRep.DataSource = ds.Tables[0];
this.ItemRep.DataBind();
}

public void checkSZ() {
if (Session["cadresId"] != null&&!"".Equals(Session["cadresId"].ToString().Trim()))
{
int cadreId = int.Parse(Session["cadresId"].ToString());
String sql = "select * from [干部详细信息表] where [干部编号]=" + cadreId + " and [状态]=1";
DataTable dt = DbHelperOleDb.GetDataSet(sql).Tables[0];
if (dt.Rows.Count == 0)
{
Response.Write("<script>alert('提示:\\n您还未提交述职报告,请尽快填写并确认提交,谢谢合作!');</script>");
}
}
}


protected void savePass_Click(object sender, EventArgs e)
{
String oldpass = this.oldpass.Text.Trim();
String newpass = this.newpass.Text.Trim();
String newpass2 = this.newpass2.Text.Trim();
if (StringUtils.isEmpty(oldpass) || StringUtils.isEmpty(newpass) || StringUtils.isEmpty(newpass2))
{
this.lb_msg.Text = "新旧密码都不能为空!";
return;
}

if (!((newpass.Length <= 20) && (newpass.Length >= 5)))
{
this.lb_msg.Text = "密码只能为5-20位!";
return;
}

if (!newpass.Equals(newpass2)) {
this.lb_msg.Text = "两次输入的新密码不一致,请检查!";
return;
}

int userid = int.Parse(Session["userId"].ToString());
String sql = "";
if ("system".Equals(Session["userType"].ToString()))//系统用户
{
sql = "select * from [管理员信息] where [编号]=@id and [密码]=@pass";
oldpass = Md5Helper.HashMD5_String(oldpass);
OleDbParameter[] OleParams = { new OleDbParameter("@id", userid), new OleDbParameter("@pass", oldpass) };
DataTable dt = DbHelperOleDb.Query(sql, OleParams).Tables[0];

if (dt.Rows.Count == 0)
{
this.lb_msg.Text = "输入的旧密码错误,请检查!";
return;
}

sql = "update [管理员信息] set [密码]=@pass where [编号]=@id";
OleDbParameter[] OleParams2 = { new OleDbParameter("@pass",Md5Helper.HashMD5_String(newpass)), new OleDbParameter("@id", userid) };
DbHelperOleDb.ExecuteSql(sql, OleParams2);

this.lb_msg.Text = "恭喜:密码修改成功!";

}

if ("user".Equals(Session["userType"].ToString()))//普通用户
{

sql = "select * from [部门用户视图] where [编号]=@id and [密码]=@pass";
OleDbParameter[] OleParams = { new OleDbParameter("@id", userid), new OleDbParameter("@pass", oldpass) };
DataTable dt = DbHelperOleDb.Query(sql, OleParams).Tables[0];
if (dt.Rows.Count == 0)
{
this.lb_msg.Text = "输入的旧密码错误,请检查!";
return;
}

sql = "update [用户信息表] set [密码]=@pass where [编号]=@id";
OleDbParameter[] OleParams2 = { new OleDbParameter("@pass", newpass), new OleDbParameter("@id", userid) };
DbHelperOleDb.ExecuteSql(sql, OleParams2);

this.lb_msg.Text = "恭喜:密码修改成功!";
}

}
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值