changepasswordapi.aspx.cs

来自「《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含」· CS 代码 · 共 69 行

CS
69
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ChangePasswordAPI : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		//检查身份是否通过验证
		if (!User.Identity.IsAuthenticated)
		{
			//导向Authentication中的loginUrl网址进行验证
			FormsAuthentication.RedirectToLoginPage();
		}
	}

	//更改用户密码
	protected void btnChangePwd_Click(object sender, EventArgs e)
	{
		//取得目前用户
		MembershipUser currentUser = Membership.GetUser(User.Identity.Name);

		try
		{
			//检查用户身份 && 新密码是否一致
			if (currentUser != null)
			{
				//新密码double check
				if (txtNewPwd1.Text == txtNewPwd2.Text)
				{
					//改变用户密码
					if (currentUser.ChangePassword(txtOldPwd.Text, txtNewPwd1.Text))
					{
						new AlertMessage().showMsg(this.Page, "更改密码成功!");
					}
					else
					{
						new AlertMessage().showMsg(this.Page, "更改密码失败!");
					}
				}
				else
				{
					new AlertMessage().showMsg(this.Page, "新输入的密码不一致!");
				}
			}
		}
		catch (Exception err)
		{
			//显示错误信息
			Response.Write(Server.HtmlEncode(err.Message));
		}

	}

	//退出
	protected void btnSignout_Click(object sender, EventArgs e)
	{
		FormsAuthentication.SignOut();
		FormsAuthentication.RedirectToLoginPage();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?