using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.SiteProvider; using CMS.UIControls; using CMS.ExtendedControls; public partial class CMSModules_Membership_FormControls_Passwords_ChangePassword : CMSUserControl { #region "Variables" protected bool mAllowEmptyPassword = false; #endregion #region "Properties" /// /// Indicates whether to allow to save empty password. /// public bool AllowEmptyPassword { get { return mAllowEmptyPassword; } set { mAllowEmptyPassword = value; } } /// /// Gets confirmation button /// public CMSButton ConfirmationButton { get { return btnOk; } } /// /// Indicates if new password must be different than previous password /// public bool ForceDifferentPassword { get; set; } /// /// If true, control does not process the data. /// public override bool StopProcessing { get { return ValidationHelper.GetBoolean(ViewState["StopProcessing"], false); } set { ViewState["StopProcessing"] = value; } } /// /// Messages placeholder /// public override MessagesPlaceHolder MessagesPlaceHolder { get { return plcMess; } } #endregion #region "Events" /// /// Event which occurs after successful password change /// public event OnPasswordChangeHandler OnPasswordChange; /// /// Successful password change event handler /// public delegate void OnPasswordChangeHandler(object sender, EventArgs e); #endregion #region "Control events" /// /// Page load. /// protected void Page_Load(object sender, EventArgs e) { if (!StopProcessing) { // Show only to authenticated users, if intended to be displayed if (Visible) { Visible = CMSContext.CurrentUser.IsAuthenticated(); } lblExistingPassword.Text = GetString("MyAccount.Password.ExistingPassword"); lblPassword1.Text = GetString("MyAccount.Password.NewPassword"); lblPassword2.Text = GetString("MyAccount.Password.ConfirmPassword"); btnOk.Text = GetString("MyAccount.Password.SetPassword"); } } /// /// On btnOK click, save changed password. /// protected void btnOK_Click(object sender, EventArgs e) { UserInfo ui = CMSContext.CurrentUser; if (ui != null) { // Check match of old password if (!UserInfoProvider.IsUserPasswordDifferent(ui, txtExistingPassword.Text)) { if ((!mAllowEmptyPassword) && (DataHelper.IsEmpty(passStrength.Text.Trim()))) { ShowError(GetString("myaccount.password.emptypassword")); } else { if (passStrength.Text == txtPassword2.Text) { // Check policy if (!passStrength.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(CMSContext.CurrentSiteName)); } else { // Check if different password is required if (ForceDifferentPassword) { if (!UserInfoProvider.IsUserPasswordDifferent(ui, passStrength.Text)) { ShowError(GetString("passreset.newpasswordrequired")); return; } } UserInfoProvider.SetPassword(ui.UserName, passStrength.Text); ShowChangesSaved(); // Call Password change event if (OnPasswordChange != null) { OnPasswordChange(this, null); } } } else { // New and confirmed password are not equal ShowError(GetString("Administration-User_Edit_Password.PasswordsDoNotMatch")); } } } else { // Incorrect existing password ShowError(GetString("myaccount.password.incorrectexistingpassword")); } } } #endregion }