private void ClientHost_PasswordRequested(PasswordRequestEventArgs args) { var message = default(TextKey); var title = default(TextKey); logger.Info($"Received input request with id '{args.RequestId}' for the {args.Purpose.ToString().ToLower()} password."); switch (args.Purpose) { case PasswordRequestPurpose.LocalAdministrator: message = TextKey.PasswordDialog_LocalAdminPasswordRequired; title = TextKey.PasswordDialog_LocalAdminPasswordRequiredTitle; break; case PasswordRequestPurpose.LocalSettings: message = TextKey.PasswordDialog_LocalSettingsPasswordRequired; title = TextKey.PasswordDialog_LocalSettingsPasswordRequiredTitle; break; case PasswordRequestPurpose.Settings: message = TextKey.PasswordDialog_SettingsPasswordRequired; title = TextKey.PasswordDialog_SettingsPasswordRequiredTitle; break; } var dialog = uiFactory.CreatePasswordDialog(text.Get(message), text.Get(title)); var result = dialog.Show(); runtime.SubmitPassword(args.RequestId, result.Success, result.Password); logger.Info($"Password request with id '{args.RequestId}' was {(result.Success ? "successful" : "aborted by the user")}."); }
private void grdvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { UsersSource.UsersRow editedRow; if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } editedRow = (UsersSource.UsersRow)(( DataRowView )UsersBindingSource [e.RowIndex]).Row; _SelectedUser = UsersDataGridView.Rows[e.RowIndex].Cells[UserNameDataGridViewTextBoxColumn.Index].Value.ToString(); if (e.ColumnIndex == NewPasswordDataGridViewButtonColumn.Index) { PasswordRequestEventArgs ea = new PasswordRequestEventArgs(); PasswordRequest(this, ea); if (!ea.Cancel) { UsersDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ea.Password; if (ea.Expires.HasValue) { UsersDataGridView.Rows[e.RowIndex].Cells[ExpiresColumn.Index].Value = ea.Expires; } else { UsersDataGridView.Rows[e.RowIndex].Cells[ExpiresColumn.Index].Value = DBNull.Value; } UsersBindingSource.EndEdit(); } } else if (e.ColumnIndex == Permissions.Index) { EditUserPermissionsEventArgs ea = new EditUserPermissionsEventArgs(_SelectedUser); UsersSource.UserPermissionsRow[] permissions = (from p in Source.UserPermissions where p.RowState != DataRowState.Deleted && p.UserName == _SelectedUser select p).ToArray(); foreach (UsersSource.UserPermissionsRow permission in permissions) { ea.Permissions.Add(permission.Permission); } EditUserPermissions(this, ea); } } catch (Exception exception) { MessageBox.Show(this, exception.Message, "User Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void UsersAccounts_PasswordRequest(object sender, PasswordRequestEventArgs e) { PasswordDialog dlgPassword = new PasswordDialog(); dlgPassword.ValidatePassword += new EventHandler <ValidatePasswordEventArgs>(dlgPassword_ValidatePassword); e.Cancel = dlgPassword.ShowDialog() == DialogResult.Cancel; if (!e.Cancel) { IOptionsDataAccessAgent agent; PasswordOptions options; agent = DataAccessFactory.GetInstance(new OptionsDataAccessConfigurationView(DicomDemoSettingsManager.GetGlobalPacsConfiguration(), DicomDemoSettingsManager.ProductNameStorageServer, null)).CreateDataAccessAgent <IOptionsDataAccessAgent>(); options = agent.Get <PasswordOptions>(PasswordOptionsPresenter.PasswordOptions, new PasswordOptions()); e.Password = dlgPassword.Password; if (options.DaysToExpire > 0) { e.Expires = DateTime.Now.AddDays(options.DaysToExpire); } View_SettingsChanged(sender, e); } }
public void Communication_MustCorrectlyHandlePasswordRequest() { var args = new PasswordRequestEventArgs { Purpose = PasswordRequestPurpose.LocalSettings, RequestId = Guid.NewGuid() }; var dialog = new Mock <IPasswordDialog>(); var result = new Mock <IPasswordDialogResult>(); dialog.Setup(d => d.Show(It.IsAny <IWindow>())).Returns(result.Object); result.SetupGet(r => r.Password).Returns("blubb"); result.SetupGet(r => r.Success).Returns(true); uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny <string>(), It.IsAny <string>())).Returns(dialog.Object); sut.TryStart(); clientHost.Raise(c => c.PasswordRequested += null, args); runtimeProxy.Verify(p => p.SubmitPassword( It.Is <Guid>(g => g == args.RequestId), It.Is <bool>(b => b == result.Object.Success), It.Is <string>(s => s == result.Object.Password)), Times.Once); }