ASP.NET Membership Provider: Changing user password without knowing the old one

If you want to change a membership user’s password with the MembershipUser.ChangePassword method you need to know the user’s old password.

The following extension method defines a SetNewPassword method that enables you to reset the password without knowing the old one:

    public static class MembershipUserExtension
        /// <summary>
        /// Set a new password for the membership user
        /// </summary>
        /// <param name="membershipUser">Membership user to extend</param>
        /// <param name="newPassword">New password</param>
        /// <returns>True if the update was successful; otherwise, false.</returns>
        public static bool SetNewPassword(this MembershipUser membershipUser, string newPassword)
            var generatedPassword = membershipUser.ResetPassword();
            return membershipUser.ChangePassword(generatedPassword, newPassword);

Please note that this method only works if the Membership Properties are defined as follows: