/// <summary> /// Change User Password. /// </summary> private void SaveBtn_Click(object sender, EventArgs e) { try { if (String.IsNullOrWhiteSpace(OriginalPasswordTB.Text)) { OriginalPasswordTB.Focus(); MessageBox.Show("原密码不能为空", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (String.IsNullOrWhiteSpace(NewPasswordTB.Text)) { NewPasswordTB.Focus(); MessageBox.Show("新密码不能为空", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!NewPasswordTB.Text.Equals(NewCPasswordTB.Text)) { NewPasswordTB.Focus(); MessageBox.Show("两次输入密码不一致", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!MemberShipEntity.CheckPassword(Common.CurUser.Password, OriginalPasswordTB.Text, Common.CurUser.PasswordFormat, Common.CurUser.PasswordSalt)) { OriginalPasswordTB.Focus(); MessageBox.Show("原密码输入错误", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var User = new UserInfo() { UserID = Common.CurUser.UserID, UserName = Common.CurUser.UserName, PasswordFormat = Common.CurUser.PasswordFormat, PasswordSalt = MemberShipEntity.GenerateSalt(), Password = NewPasswordTB.Text.Trim(), LastPasswordChangedDate = DateTime.Now }; User.Password = MemberShipEntity.EncodePassword(User.Password, User.PasswordFormat, User.PasswordSalt); MemberShipEntity.ChangePassword(User); Common.CurUser.Password = User.Password; Common.CurUser.PasswordSalt = User.PasswordSalt; Common.CurUser.LastPasswordChangedDate = User.LastPasswordChangedDate; MessageBox.Show("密码修改完成,下次登录请使用新密码。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Common.WriteLog(DateTime.Now, EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.ChangePasswordForm.SaveBtn.Click", String.Format("用户[{0}]修改密码", User.UserName), null); this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception err) { Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.ChangePasswordForm.SaveBtn.Click", err.Message, err.StackTrace); MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool ChangePassword([FromBody] AccountSign entity) { if (entity == null || string.IsNullOrEmpty(entity.Password)) { return(false); } var isChanged = MemberShip.ChangePassword(MvcContext.Current.PassportId, entity.Password); return(isChanged); }
public AccountSignResult ResetPassword(AccountSign entity) { if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) || string.IsNullOrEmpty(entity.Password) || string.IsNullOrEmpty(entity.ValidationCode)) { return(null); } var account = MvcContext.Current.ClientAccount; if (null == account) { return(null); } var isValid = MessageHelper.CheckSMSValidationCode(entity.MobilePhone, entity.ValidationCode); if (MvcContext.Current.Test && entity.ValidationCode == AppEnvironment.TestValidationCode) { isValid = true; } if (false == isValid) { return(new AccountSignResult() { SignStatus = SignStatus.InvalidValidationCode, ErrorMessage = "验证码无效,请重新获取" }); } var passportId = UserPassport.FindIdByMobilePhone(entity.MobilePhone); if (passportId < 1) { return(new AccountSignResult() { SignStatus = SignStatus.InvalidMobilePhone, ErrorMessage = "手机号未注册" }); } var isChanged = MemberShip.ChangePassword(passportId, entity.Password); if (isChanged) { return(new AccountSignResult() { SignStatus = SignStatus.Success }); } return(new AccountSignResult() { SignStatus = SignStatus.Failed }); }
public void ChangePasswordTest() { var password = string.Format("P{0}", TestHelper.GetRndNumber(10000, 90000)); var passport = SignUp(password); Assert.IsTrue(MemberShip.SignIn(passport.MobilePhone, password)); var newPassword = string.Format("NP{0}", TestHelper.GetRndNumber(10000, 90000)); var chanedResult = MemberShip.ChangePassword(passport.PassportId, newPassword); Assert.IsTrue(chanedResult); Assert.IsFalse(MemberShip.SignIn(passport.MobilePhone, password)); Assert.IsTrue(MemberShip.SignIn(passport.MobilePhone, newPassword)); }
/// <summary> /// Save User. /// </summary> private void SaveBtn_Click(object sender, EventArgs e) { try { if (String.IsNullOrWhiteSpace(UserNameTB.Text)) { UserNameTB.Focus(); MessageBox.Show("用户名不能为空", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var UserName = UserNameTB.Text.Trim(); if (CurBehavior == EnmSaveBehavior.Add || (CurBehavior == EnmSaveBehavior.Edit && !CurUser.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase))) { if (MemberShipEntity.UserExists(UserName)) { UserNameTB.Focus(); MessageBox.Show("用户名已存在", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (CurBehavior == EnmSaveBehavior.Add || (CurBehavior == EnmSaveBehavior.Edit && UserPasswordCB.Checked)) { if (String.IsNullOrWhiteSpace(UserPasswordTB.Text)) { UserPasswordTB.Focus(); MessageBox.Show("密码不能为空", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!UserPasswordTB.Text.Equals(UserCPasswordTB.Text)) { UserPasswordTB.Focus(); MessageBox.Show("两次输入密码不一致", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (!String.IsNullOrWhiteSpace(UserMobileTB.Text) && !Regex.IsMatch(UserMobileTB.Text.Trim(), @"^1[358][0-9]{9}$", RegexOptions.IgnoreCase)) { UserMobileTB.Focus(); MessageBox.Show("请输入正确的手机号码", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!String.IsNullOrWhiteSpace(UserEmailTB.Text) && !Regex.IsMatch(UserEmailTB.Text.Trim(), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$", RegexOptions.IgnoreCase)) { UserEmailTB.Focus(); MessageBox.Show("请输入正确的Email", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!NeverCB.Checked && UserLimitDTP.Value <= DateTime.Now) { UserLimitDTP.Focus(); MessageBox.Show("用户有效日期无效,请选择大于当前时间的有效日期。", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (CurBehavior == EnmSaveBehavior.Add) { CurUser.Role.RoleID = (Guid)UserRoleCB.SelectedValue; CurUser.Role.RoleName = UserRoleCB.Text; CurUser.UserName = UserNameTB.Text.Trim(); CurUser.RemarkName = UserRemarkNameTB.Text.Trim(); CurUser.Password = MemberShipEntity.EncodePassword(UserPasswordTB.Text.Trim(), CurUser.PasswordFormat, CurUser.PasswordSalt); CurUser.MobilePhone = UserMobileTB.Text.Trim(); CurUser.Email = UserEmailTB.Text.Trim(); CurUser.CreateDate = DateTime.Now; CurUser.LimitDate = NeverCB.Checked ? new DateTime(2099, 12, 31) : UserLimitDTP.Value; CurUser.LastLoginDate = ComUtility.DefaultDateTime; CurUser.LastPasswordChangedDate = ComUtility.DefaultDateTime; CurUser.FailedPasswordAttemptCount = 0; CurUser.IsLockedOut = false; CurUser.LastLockoutDate = ComUtility.DefaultDateTime; CurUser.Comment = UserCommentTB.Text.Trim(); CurUser.Enabled = UserStatusCB.Checked; var result = Common.ShowWait(() => { MemberShipEntity.CreateUser(CurUser); }, default(String), "正在保存,请稍后...", default(Int32), default(Int32)); if (result == DialogResult.OK) { Common.CopyObjectValues(CurUser, OriUser); Common.WriteLog(DateTime.Now, EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.SaveUserForm.SaveBtn.Click", String.Format("新增用户:[{0}]", CurUser.UserName), null); MessageBox.Show("数据保存完成", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("数据保存失败", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (CurBehavior == EnmSaveBehavior.Edit) { var IsChangePwd = UserPasswordCB.Checked; if (!IsChangePwd || MessageBox.Show("您确定要重置用户密码吗?", "确认对话框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { CurUser.Role.RoleID = (Guid)UserRoleCB.SelectedValue; CurUser.Role.RoleName = UserRoleCB.Text; CurUser.UserName = UserNameTB.Text.Trim(); CurUser.RemarkName = UserRemarkNameTB.Text.Trim(); if (IsChangePwd) { CurUser.PasswordFormat = EnmPasswordFormat.Hashed; CurUser.PasswordSalt = MemberShipEntity.GenerateSalt(); CurUser.Password = MemberShipEntity.EncodePassword(UserPasswordTB.Text.Trim(), CurUser.PasswordFormat, CurUser.PasswordSalt); CurUser.LastPasswordChangedDate = DateTime.Now; } CurUser.MobilePhone = UserMobileTB.Text.Trim(); CurUser.Email = UserEmailTB.Text.Trim(); CurUser.LimitDate = NeverCB.Checked ? new DateTime(2099, 12, 31) : UserLimitDTP.Value; CurUser.Comment = UserCommentTB.Text.Trim(); CurUser.Enabled = UserStatusCB.Checked; var result = Common.ShowWait(() => { MemberShipEntity.SaveUser(CurUser); if (IsChangePwd) { MemberShipEntity.ChangePassword(CurUser); } }, default(string), "正在保存,请稍后...", default(int), default(int)); if (result == DialogResult.OK) { Common.CopyObjectValues(CurUser, OriUser); Common.WriteLog(DateTime.Now, EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.SaveUserForm.SaveBtn.Click", String.Format("更新用户:[{0}]", CurUser.UserName), null); MessageBox.Show("数据保存完成", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("数据保存失败", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch (Exception err) { Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.SaveUserForm.SaveBtn.Click", err.Message, err.StackTrace); MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }