public void TestPasswordType() { PasswordValidationRule passVR = new PasswordValidationRule(); CultureInfo cultureInfo = new CultureInfo("ru-RU"); Assert.IsInstanceOfType(passVR.Validate("Root123", cultureInfo), typeof(ValidationResult)); }
public CreateAccountOperationValidationRule() { this._passwordValidationRule = new PasswordValidationRule(); this._loginValidationRule = new LoginValidationRule(); this._emailValidationRule = new EmailValidationRule(); this._phoneValidationRule = new PhoneValidationRule(); }
private void OnPasswordChanged(object sender, RoutedEventArgs e) { var box = sender as PasswordBox; var validateResult = new PasswordValidationRule().Validate(box.Password, null); if (validateResult.IsValid == false) { PasswordValidattion.SetHasError(box, true); PasswordValidattion.SetErrorMessage(box, validateResult.ErrorContent.ToString()); return; } if (repeatedRegisteredPasswordBox == box || registeredPasswordBox == box) { if (repeatedRegisteredPasswordBox.Password != registeredPasswordBox.Password) { PasswordValidattion.SetHasError(repeatedRegisteredPasswordBox, true); PasswordValidattion.SetErrorMessage(repeatedRegisteredPasswordBox, "两次输入密码不一致!"); PasswordValidattion.SetHasError(registeredPasswordBox, false); PasswordValidattion.SetErrorMessage(registeredPasswordBox, null); } else { PasswordValidattion.SetHasError(repeatedRegisteredPasswordBox, false); PasswordValidattion.SetErrorMessage(repeatedRegisteredPasswordBox, null); PasswordValidattion.SetHasError(registeredPasswordBox, false); PasswordValidattion.SetErrorMessage(registeredPasswordBox, null); } return; } PasswordValidattion.SetHasError(box, false); PasswordValidattion.SetErrorMessage(box, null); }
public void PasswordValidationReturnsFalse(string password) { PasswordValidationRule passwordValidationRule = new PasswordValidationRule(password); bool expected = false; bool actual = passwordValidationRule.Validate(); Assert.AreEqual(expected, actual); }
public void TestBadPassword() { PasswordValidationRule passVR = new PasswordValidationRule(); CultureInfo cultureInfo = new CultureInfo("ru-RU"); var actual = passVR.Validate("rot", cultureInfo); var expected = new ValidationResult(false, "Пароль должен содержать:\nХотя бы одно число\nХотя бы одну латинскую букву в верхнем и нижнем регистре\nСтрока не менее 6 символов"); Assert.AreEqual(expected, actual); }
public void TestGoodPassword() { PasswordValidationRule passVR = new PasswordValidationRule(); CultureInfo cultureInfo = new CultureInfo("ru-RU"); var actual = passVR.Validate("Root123", cultureInfo); var expected = new ValidationResult(false, null); Assert.AreNotEqual(expected, actual); }
public void TestPasswordRegex_False() { // arrange var passwordValidationRule = new PasswordValidationRule(); // act var result = passwordValidationRule.Validate("Test12", CultureInfo.CurrentCulture); // assert Assert.IsFalse(result.IsValid); }
private void DoLogin(object commandArg) { SetLoginState(true); LoginInfoArgs infoArgs = commandArg as LoginInfoArgs; bool bValidated = true; if (!AccountValidationRule.Validate(infoArgs.AccountControl.Text)) { _eventAggregator.GetEvent <InputErrorEvent>().Publish(new InputErrorEventArgs(InputErrorKinds.Account)); bValidated = false; } //#if DEBUG if (!PasswordValidationRule.Validate(infoArgs.PasswordControl.Password)) //#else // if (!PasswordValidationRule.Validate(infoArgs.PasswordControl.SecurePassword)) //#endif { _eventAggregator.GetEvent <InputErrorEvent>().Publish(new InputErrorEventArgs(InputErrorKinds.Password)); bValidated = false; } if (bValidated) { try { #if DEBUG LoginInfo info = new LoginInfo(infoArgs.AccountControl.Text, infoArgs.PasswordControl.Password, infoArgs.IP); #else LoginInfo info = new LoginInfo(infoArgs.AccountControl.Text, infoArgs.PasswordControl.SecurePassword, infoArgs.IP); #endif _lighterContext.AccountLogin(info, new InstanceContext(_loginCallback)); } catch (ServerClosedException ex) { SetLoginMessage(ex.Message); _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.Closed, ex.Message)); } catch (ServerNotFoundException ex) { SetLoginMessage(ex.Message); _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.NotFound, ex.Message)); } catch (ServerTooBusyException ex) { SetLoginMessage(ex.Message); _eventAggregator.GetEvent <ServiceEvent>().Publish(new ServiceEventArgs(ServiceEventKind.TooBusy, ex.Message)); } } SetLoginState(false); }
public bool Validate() { var validationResult = true; var emailValidation = new EmailValidationRule(); var loginValidation = new LoginValidationRule(); var passwordValidation = new PasswordValidationRule(); validationResult &= emailValidation.Validate(Email, null).IsValid; validationResult &= loginValidation.Validate(Login, null).IsValid; validationResult &= passwordValidation.Validate(Password, null).IsValid; return(validationResult); }
private bool CheckMsg(MainConfig config, Message msg, out string error) { try { var realMsg = msg as MessageRegisterRequest; UIUser realUser = FindUser(config, realMsg.Account); if (null != realUser) { throw new Exception("账号已存在"); } var validateResult = new AccountValidationRule().Validate(realMsg.Account, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } validateResult = new PasswordValidationRule().Validate(realMsg.Password, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } validateResult = new NameValidationRule().Validate(realMsg.Name, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } validateResult = new IntroduceValidationRule().Validate(realMsg.Introduce, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } error = null; return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
private void SetupPasswordValidation() { m_PasswordValidationRule = new PasswordValidationRule(); m_ConfirmPasswordValidationRule = new ConfirmPasswordValidationRule(m_PasswordBox); m_PasswordBox.Tag = m_PasswordBox.PasswordChar; var validationBinding = new Binding { Source = m_PasswordBox, Path = new PropertyPath("Tag") }; validationBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(m_PasswordBox, PasswordBox.PasswordCharProperty, validationBinding); m_ConfirmPasswordBox.Tag = m_ConfirmPasswordBox.PasswordChar; validationBinding = new Binding { Source = m_ConfirmPasswordBox, Path = new PropertyPath("Tag") }; validationBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(m_ConfirmPasswordBox, PasswordBox.PasswordCharProperty, validationBinding); PasswordBox_PasswordChanged(this, null); ConfirmPasswordBox_PasswordChanged(this, null); }
public EnterOperationValidationRule() { passwordValidationRule = new PasswordValidationRule(); loginValidationRule = new LoginValidationRule(); }
public LoginOperationValidationRule() { this.passwordValidationRule = new PasswordValidationRule(); this.loginValidationRule = new LoginValidationRule(); }
private void OnApplyRegister(object sender, RoutedEventArgs e) { try { //检查注册信息 if (userHead.Source == null) { throw new Exception("请上传头像!"); } var validateResult = new AccountValidationRule().Validate(RegisteredAccount, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } if (repeatedRegisteredPasswordBox.Password != registeredPasswordBox.Password) { throw new Exception(PasswordValidattion.GetErrorMessage(repeatedRegisteredPasswordBox)); } validateResult = new PasswordValidationRule().Validate(RegisteredPassword, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } validateResult = new NameValidationRule().Validate(RegisteredName, null); if (validateResult.IsValid == false) { throw new Exception(validateResult.ErrorContent.ToString()); } //连接网络 if (_protocol.IsConnected == false) { _protocol.Connect(); } if (_protocol.IsConnected == false) { return; } //填写消息 var msg = new MessageRegisterRequest() { CallID = DateTime.Now.GetHashCode(), UserID = Account.GetHashCode(), Account = RegisteredAccount, Password = RegisteredPassword, Name = RegisteredName, Introduce = RegisteredIntroduce, User = _protocol.UserList.First().Value }; var encoder = new BmpBitmapEncoder(); var bitmapSource = this.userHead.Source as BitmapSource; encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); using (var stream = new MemoryStream()) { encoder.Save(stream); msg.HeadsculptStream = stream.GetBuffer(); } //发送 string error = null; bool result = false; using (var signal = new ManualResetEventSlim()) { EventHandler <Message> waitBack = (object sd, Message respondsMsg) => { if (msg.CallID != respondsMsg.CallID) { return; } if (respondsMsg.MessageID == MessageID.MI_REGISTER_FAILED) { error = (respondsMsg as MessageRegisterFailed).Error; signal.Set(); } else if (respondsMsg.MessageID == MessageID.MI_REGISTER_SUCCESSFULLY) { var realMsg = (respondsMsg as MessageRegisterSuccessfully); result = true; signal.Set(); } }; this._protocol.MessageEvent += waitBack; this._protocol.SendBigMsg(msg); if (signal.Wait(2000) == false) { error = "服务器没有响应,请重试!"; } this._protocol.MessageEvent -= waitBack; } if (result == false) { throw new Exception(error); } MessageWindow.Show(this, "注册成功,赶紧登录去吧!"); this.OnLoginState(); } catch (Exception ex) { MessageWindow.Show(this, ex.Message); } _protocol.Disconnect(); }