本文整理汇总了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;
}
示例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;
}
示例3: ChangePassword
public void ChangePassword(MembershipUser user, string oldPassword, string newPassword)
{
if (!user.ChangePassword(oldPassword, newPassword))
throw new MembershipPasswordException("Could not change password.");
}
示例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);
}
示例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);
}
示例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();
}
}
示例7: ChangePassword
public bool ChangePassword(MembershipUser user, string oldPassword, string newPassword)
{
return user.ChangePassword(oldPassword, newPassword);
}
示例8: ChangePassword
public void ChangePassword(MembershipUser membershipUser, string newPassword)
{
string tempPassword = membershipUser.ResetPassword();
membershipUser.ChangePassword(tempPassword, newPassword);
}
示例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;
}
示例10: ChangePassword
public virtual bool ChangePassword(MembershipUser membershipUser, string oldPassword, string newPassword)
{
return membershipUser.ChangePassword(oldPassword, newPassword);
}