Category Archives: ChangePassword

[RESOLVED] MVP (Model View Presenter) & asp:createuserwizard

hello,

in order to develop a application based on MVP (Model View Presenter) pattern  can I  use asp:createuserwizard, asp:changepassword and .NET security module?

If is possible I need some examples or links.

Thanks. 

Since the .Net controls mentioned integrate with the Security Provider model, your Presenters will be used in the Provider along with a ServiceObject (playing the role of the View) and, of course the database would hold the Model.

check following

http://www.c-sharpcorner.com/UploadFile/raj1979/CreateUserWizard08042008224747PM/CreateUserWizard.aspx

Problem with asp:changepassword control while giving invalid current password

Hi,

I am using membership database for authentication and on one of my form, I allow to change user password.

And for that, I am using asp:changepassword control. My problem is that when I give correct old / current password, it displays fine and changes password correctly. But if I give invalid current password then I want to display this message that "Entered current password is invalid". Its not showing this message. Its not showing any thing. I tried using its some of the properties but its not showing any message when I give invalid current password and nothing happens. Its not even firing OnChangedPassword event.

I am giving my simple code as under. And here is what I want to do.

1. I want to display a message when entered current password is not valid.

2. I want to display message when password is changed successfully, At present, after success, it shows "Continue" button. I do not want to show that button and just want to display message that "Password has been changed successfully".

###########################################################################

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
      <asp:changepassword id="ChangePassword1" runat="server"
              PasswordHintText = "Please enter a password at least 7 characters long, containing a number and one special character."
              NewPasswordRegularExpression = '^.*(?=.{7,})(?=.*[a-zA-Z])(?=.*[@#$%^&!+=]).*$'
              NewPasswordRegularExpressionErrorMessage = "Your password must be at least 7 characters long,
                                                        and contain at least one number and one special character."
              OnCancelButtonClick="OnCancel_Click"
              OnChangedPassword="OnPasswordChanged_Click"
              Width="707px"
              ContinueDestinationPageUrl="~/customerportal/ldaportal.aspx"
              ChangePasswordFailureText="Password change failed. Please re-enter your values and try again."
              

              >




            <ChangePasswordTemplate>
                <center><h1>Change Password</h1></center>


<table style="width: 100%;">
<tr>
<td style="width: 150px" align="right"></td>
<td align="left">Please enter a password at least 7 characters long, containing atleaset one numeric and one special character.<br /></td>
</tr>
<tr>
<td style="width: 150px" align="right">
                <asp:Label
                    id="lblCurrentPassword"
                    Text="Current Password:"
                    AssociatedControlID="CurrentPassword"
                    Runat="server" />
</td>
<td align="left">
                 <asp:TextBox
                    id="CurrentPassword"
                    TextMode="Password"
                    Runat="server" />
                    

                 <asp:RequiredFieldValidator
                   ID="ValCurrentPassword"
                   ControlToValidate="CurrentPassword"
                   Text="*"
                   runat="server">
                 </asp:RequiredFieldValidator>
                  

</td>
</tr><tr>
<td align="right">


                <asp:Label
                    id="lblChangePassword"
                    Text="New Password:"
                    AssociatedControlID="NewPassword"
                    Runat="server" />
</td>
<td>
                <asp:TextBox
                    id="NewPassword"
                    TextMode="Password"
                    Runat="server" />
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                   ControlToValidate="NewPassword"
                   Text="*"
                   runat="server">
                 </asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
                <asp:Label
                    id="lblConfirmPassword"
                    Text="Confirm New Password:"
                    AssociatedControlID="ConfirmPassword"
                    Runat="server" />
</td><td>
                <asp:TextBox
                    id="ConfirmPassword"
                    TextMode="Password"
                    Runat="server" />
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
                   ControlToValidate="ConfirmPassword"
                   Text="*"
                   runat="server">
                 </asp:RequiredFieldValidator>
</td>
</tr>
 <tr>
 <td></td>
 <td>
                    

                <br />
                <br />
                                

                <asp:Button
                    id="btnChangePassword"
                    Text="Change Password"
                    CommandName="ChangePassword"
                    Runat="server" />


                <asp:Button
                    id="btnCancelPassword"
                    Text="Cancel"
                    CommandName="Cancel"
                    CausesValidation="false"
                    Runat="server" />
</td>
</tr>
</table>
                <br />
                <asp:CompareValidator ID="NewPasswordValidator"
                    runat="server"
                    ErrorMessage="The passwords do not match!"
                    ControlToCompare="NewPassword"
                    ControlToValidate="ConfirmPassword">
                    </asp:CompareValidator>
                <br />
                <asp:Label
                    id="lblMessage"
                    EnableViewState="false"
                    ForeColor="Red"
                    Runat="server" />
            </ChangePasswordTemplate>






              </asp:changepassword>
              

                            

                                        

</asp:Content>


 

Code Behind:

 protected void OnPasswordChanged_Click(object sender, EventArgs e)
    {
        Label lblMessage =
            ChangePassword1.ChangePasswordTemplateContainer.FindControl("lblMessage") as Label;

        try
        {

            TextBox txtCurrentPassword =
                ChangePassword1.ChangePasswordTemplateContainer.FindControl("CurrentPassword") as TextBox;
            MembershipUser u = Membership.GetUser(User.Identity.Name);
            bool result = u.ChangePassword(txtCurrentPassword.Text,
                                              ChangePassword1.NewPassword);


            if (result == true)
            {
                if (lblMessage != null)
                {
                    lblMessage.Text = "Password successfully changed.";
                }
            }
            else
            {
                if (lblMessage != null)
                {
                    lblMessage.Text = "Password change failed. Please re-enter your values and try again.";
                }
            }

        }
        catch (Exception e1)
        {
            lblMessage.Text = e1.Message;
        }
    }



 

 

###########################################################################

Hi Niravparekh,

I think your problem might be because you use your own password form template. Just make just that the asp control (label?) holding the error/success message is rendered.

If I were you, I would give it a try without your custom template (with does nice validations) and I would look at the rendered HTML in order to see what is the missing item which is supposed to hold those messages. After identifying it you we be able to add it up to your own custom template.

niravparekh

I want to display message when password is changed successfully, At present, after success, it shows "Continue" button. I do not want to show that button and just want to display message that "Password has been changed successfully".

Besides, "ChangePasswordFailureText" is the proper property to store the failure message and you did it properly; but you should also use "SuccessText" property to put your change confirmation message. The problem, now is to render a item to hold these messages.

 

Oh Thanks a lot.

I just deleted  "ChangePasswordTemplate" and it worked fine, basically the way I expected.

The only thing I want to do now is to avoid displaying "Continue" botton after successfully change.

Now its just like this.

<asp:changepassword id="ChangePassword1" runat="server"
              PasswordHintText = "Please enter a password at least 7 characters long, containing a number and one special character."
              NewPasswordRegularExpression = '^.*(?=.{7,})(?=.*[a-zA-Z])(?=.*[@#$%^&!+=]).*$'
              NewPasswordRegularExpressionErrorMessage = "Your password must be at least 7 characters long,
                                                        and contain at least one number and one special character."
              OnCancelButtonClick="OnCancel_Click"
              OnChangedPassword="OnPasswordChanged_Click"
              Width="707px"
              ContinueDestinationPageUrl="~/customerportal/ldaportal.aspx"
              ChangePasswordFailureText="Password change failed. Please re-enter your values and try again."
              SuccessText="Password has been changed successfully."
              

              >




</asp:changepassword>


###############################################

Code behind is same and its working fine, but its still showing Continue button after successfully change, how can I avoid displaying "Continuue" button?

niravparekh

how can I avoid displaying "Continuue" button?
 

 

Easy, just hide it using CSS! for example

        .Invisible
        {
            visibility:hidden;
        }

in your asp:changepassword control declaration, add:

       ContinueButtonStyle-CssClass = "Invisible"

First of all, Thanks for  reply. I tried this but it does not display anything after successful change. Neither Continue botton nor the original screen, it just displays message of "password has been changed successfully."

What I want to do is basically by default there are 3 fields, password, new password and confirm password and two buttons - Change Password and Cancel.

When user clicks on Change Password, it changes password successfully and then displays message "Password has been change successfully" and with that it displays "Continue" Button. I just want to be on the same screen, the same above screen. I just want to display message on successful change, do not want to hide all the controls.

hi 

niravparekh, have you find a solution?? i have the same problem...