当前位置: 首页>>代码示例>>C#>>正文


C# MembershipUser.ChangePassword方法代码示例

本文整理汇总了C#中System.Web.Security.MembershipUser.ChangePassword方法的典型用法代码示例。如果您正苦于以下问题:C# MembershipUser.ChangePassword方法的具体用法?C# MembershipUser.ChangePassword怎么用?C# MembershipUser.ChangePassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Security.MembershipUser的用法示例。


在下文中一共展示了MembershipUser.ChangePassword方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangePassword

        /// <summary>
        /// Change user password
        /// </summary>
        /// <param name="member">Member</param>
        /// <param name="oldPassword">Old password</param>
        /// <param name="newPassword">New Password</param>
        /// <returns>Success status</returns>
        public bool ChangePassword(MembershipUser member, string oldPassword, string newPassword)
        {
            bool changeSucceed;
            var passwordHistoryService = new PasswordsHistoryService();

            if (member == null || !Membership.ValidateUser(member.UserName, oldPassword))
                throw new Exception("The password you entered does not match our records, please try again.");
            // Verify that username and password arent the same.
            if (member.UserName == newPassword)
                throw new Exception("Password cannot be the same as Username");
            if (string.Compare(oldPassword, newPassword, StringComparison.Ordinal) == 0)
                throw new Exception("Your new password cannot be the same as your current password.");

            try
            {
                var memberId = (int) member.ProviderUserKey;
                if (passwordHistoryService.CheckUserPassword(memberId, newPassword))
                {
                    changeSucceed = member.ChangePassword(oldPassword, newPassword);
                    // if password was changed save it to the history
                    if (changeSucceed)
                        passwordHistoryService.Add(memberId, newPassword);
                    // Update the User profile in the database
                    Membership.UpdateUser(member);
                }
                else
                {
                    // Reads Change Password page node
                    var page = ((DynamicPublishedContent)_helper.ContentAtRoot().First())
                        .Descendant("ChangePassword");
                    var message = page.GetPropertyValue<string>("lastPasswordsValidationMessage");
                    throw new Exception(message);
                }
            }
            catch (MembershipPasswordException)
            {
                throw new Exception("The password is not strong enough");
            }
            catch(Exception ex)
            {
                // Create an error message with sufficient info to contact the user
                string additionalInfo = "User " + member.UserName + " was unable to change their password.";
                // Add the error message to the log4net output
                GlobalContext.Properties["additionalInfo"] = additionalInfo;
                logger.Error(ex);
                throw;
            }
            return changeSucceed;
        }
开发者ID:HRINY,项目名称:HRI-Umbraco,代码行数:56,代码来源:UserService.cs

示例2: ChangePassword

        /// <summary>
        /// Changes password and removes hash from DDS
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newPassword"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public bool ChangePassword(MembershipUser user, string newPassword, string hash)
        {
            bool success = false;
            //change password
            if (user != null)
            {
                // reset password to retrieve current password
                string resetPw = user.ResetPassword();
                success = user.ChangePassword(resetPw, newPassword);
                // clean up - remove reset link from dds
                if (!string.IsNullOrEmpty(hash))
                    _resetPasswordRespository.Delete(hash);
            }

            return success;
        }
开发者ID:smchristenson,项目名称:CommerceStarterKit,代码行数:23,代码来源:ResetPasswordService.cs

示例3: ChangePassword

 public void ChangePassword(MembershipUser user, string oldPassword, string newPassword)
 {
     if (!user.ChangePassword(oldPassword, newPassword))
         throw new MembershipPasswordException("Could not change password.");
 }
开发者ID:dogbrain,项目名称:MVC3NHibernateNinjectNLog,代码行数:5,代码来源:AspNetMembershipProviderWrapper.cs

示例4: ChangePassword

		/// <summary>
        /// Change user password
        /// </summary>
        /// <param name="password"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        bool ChangePassword(MembershipUser user, string password, string newPassword)
        {
            return user.ChangePassword(password, newPassword);
        }
开发者ID:ildragocom,项目名称:BlogEngine.NET,代码行数:10,代码来源:UsersRepository.cs

示例5: ChangePassword

 /// <summary>
 /// Change user password
 /// </summary>
 /// <param name="user">Membership user</param>
 /// <param name="newPassword">new password</param>
 /// <returns>Return true if password changed</returns>
 public bool ChangePassword(MembershipUser user, string newPassword)
 {
     return user.ChangePassword(user.ResetPassword(), newPassword);
 }
开发者ID:ognjenm,项目名称:egle,代码行数:10,代码来源:EviivoMembership.cs

示例6: lbtnSave_Click

 /// <summary>
 /// this method is used to change the user password  //Developed by swaraj on 19 feb 2010
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void lbtnSave_Click(object sender, EventArgs e)
 {
     try
     {
         objMembershipUser = Membership.GetUser(User.Identity.Name);
         if (Membership.ValidateUser(User.Identity.Name.ToString(), txtOldPwd.Text.ToString()))
         {
             objMembershipUser.ChangePassword(txtOldPwd.Text.ToString(), txtNewPwd.Text.ToString());
             lblMsg.ForeColor = System.Drawing.Color.Green;
             lblMsg.Text = "Password has been changed successfully";
             txtNewPwd.Text = "";
             txtOldPwd.Text = "";
             txtConfirmPwd.Text = "";
         }
         else
         {
             lblMsg.ForeColor = System.Drawing.Color.Red;
             lblMsg.Text = "Entered old password is incorrect";
         }
     }
     catch (Exception ex)
     {
         lblMsg.ForeColor = System.Drawing.Color.Red;
         lblMsg.Text = ex.Message.ToString();
     }
 }
开发者ID:shekar348,项目名称:1PointOne,代码行数:31,代码来源:AccountSettings.aspx.cs

示例7: ChangePassword

 public bool ChangePassword(MembershipUser user, string oldPassword, string newPassword)
 {
     return user.ChangePassword(oldPassword, newPassword);
 }
开发者ID:EdsonF,项目名称:nextra,代码行数:4,代码来源:MembershipFacade.cs

示例8: ChangePassword

 public void ChangePassword(MembershipUser membershipUser, string newPassword)
 {
     string tempPassword = membershipUser.ResetPassword();
     membershipUser.ChangePassword(tempPassword, newPassword);
 }
开发者ID:fschwiet,项目名称:FschwietMembershipStarterKit,代码行数:5,代码来源:AspNetMembershipProviderWrapper.cs

示例9: ChangeUserPassword

        public static bool ChangeUserPassword(MembershipUser user, string newPassword, string verificationId)
        {
            try
            {
                string newPass = string.Empty;
                try
                {
                    newPass = user.ResetPassword();
                }
                catch (Exception exception)
                {
                    if (exception.Message.Contains("user account has been locked out"))
                    {
                        user.UnlockUser();
                        newPass = user.ResetPassword();
                    }
                    else
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                }
                bool changed = user.ChangePassword(newPass, newPassword);
                var tempUser = GetMember(user.UserName);

                SendEmailForPasswordChanged(user.Email, tempUser.DerbyName);
                var dc = new ManagementContext();
                var verify = dc.EmailVerifications.Where(x => x.VerificationId == new Guid(verificationId)).FirstOrDefault();
                if (verify != null)
                {
                    dc.EmailVerifications.Remove(verify);
                    int c = dc.SaveChanges();
                }
                return changed;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());

            }
            return false;
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:39,代码来源:User.cs

示例10: ChangePassword

 public virtual bool ChangePassword(MembershipUser membershipUser, string oldPassword, string newPassword)
 {
     return membershipUser.ChangePassword(oldPassword, newPassword);
 }
开发者ID:chrisharrington,项目名称:LogWhatever,代码行数:4,代码来源:AspMembership.cs


注:本文中的System.Web.Security.MembershipUser.ChangePassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。