//Action when selecting text boxes and password boses private void passwordTextBox_GotFocus(object sender, RoutedEventArgs e) { PasswordBox selectedBox = sender as PasswordBox; selectedBox.SelectAll(); selectedBox.Background = new SolidColorBrush(Colors.White); }
public Login() { InitializeComponent(); this.DataContext = ApplicationObject.App.Config; InfoDir = System.IO.Path.Combine(Environment.CurrentDirectory, "Info"); if (!System.IO.Directory.Exists(InfoDir)) { System.IO.Directory.CreateDirectory(InfoDir); } var logDir = System.IO.Path.Combine(Environment.CurrentDirectory, "Log"); if (!System.IO.Directory.Exists(logDir)) { System.IO.Directory.CreateDirectory(logDir); } ReadLastUser(out string name, out string password); NameTextBox.Text = name; PasswordBox.Password = password; Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { PasswordBox.Focus(); PasswordBox.SelectAll(); })); CheckUpdate(); }
private void passwordTextBox_GotMouseCapture(object sender, MouseEventArgs e) { PasswordBox selectedBox = sender as PasswordBox; selectedBox.SelectAll(); selectedBox.Background = new SolidColorBrush(Colors.White); }
private void LoginButton_Click(object sender, RoutedEventArgs e) { // Try authenticating with given username and password var uaHandler = new SecurityHandler(); //var user = uaHandler.TryAuthentication(UsernameTextBox.Text, PasswordBox.Password); var user = uaHandler.TryAuthentication("piyal", "piyal123"); // If user returned is null, show error and return if (user == null) { MessageBox.Show("Invalid username or password", "Error", MessageBoxButton.OK); PasswordBox.Focus(); PasswordBox.SelectAll(); return; } // Else assign it to currentuser and show home window Session.CurrentUser = user; Session.Clearance = new Clearance(user.AccessMode); if (Session.CurrentUser.IsDefaultPassword()) { new ChangePasswordDialog().ShowDialog(); } new HomeWindow().Show(); Close(); }
public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { // If we don't have a control, return if (sender is TextBoxBase) { TextBoxBase control = (TextBoxBase)sender; if ((bool)e.NewValue) { // Focus this control control.Focus(); // Select all text control.SelectAll(); } } if (sender is PasswordBox) { PasswordBox password = (PasswordBox)sender; if ((bool)e.NewValue) { // Focus this control password.Focus(); // Select all text password.SelectAll(); } } }
protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) { base.OnPreviewGotKeyboardFocus(e); if (passwordBox != null) { passwordBox.SelectAll(); } }
private void passwordBox_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) { if (sender is PasswordBox) { PasswordBox textBox = sender as PasswordBox; textBox.SelectAll(); } }
public LoginView() { InitializeComponent(); Loaded += OnLoaded; UserIdTextBox.GotFocus += (_, __) => UserIdTextBox.SelectAll(); PasswordBox.GotFocus += (_, __) => PasswordBox.SelectAll(); TotpTextBox.GotFocus += (_, __) => TotpTextBox.SelectAll(); }
public static void SelectPassword(object sender, RoutedEventArgs e) { PasswordBox tb = (sender as PasswordBox); if (tb != null) { tb.SelectAll(); } }
public void PasswordFailure(string errorMessage) { KeyImage.Visibility = System.Windows.Visibility.Hidden; ShieldImage.Visibility = System.Windows.Visibility.Hidden; BrokenImage.Visibility = System.Windows.Visibility.Visible; ShowError(errorMessage); PasswordBox.SelectAll(); }
private void Password_GetFocus(object sender, RoutedEventArgs e) { PasswordBox tb = sender as PasswordBox; if (tb != null) { tb.SelectAll(); } }
private void Password_GotFocus(object sender, RoutedEventArgs e) { if (sender != null) { PasswordBox passwordBox = sender as PasswordBox; passwordBox.SelectAll(); passwordBox.PreviewMouseDown -= new MouseButtonEventHandler(Password_PreviewMouseDown); } }
private void password_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { PasswordBox t = sender as PasswordBox; if (t.Password != "") { t.SelectAll(); } }
protected override void OnGotFocus(RoutedEventArgs e) { base.OnGotFocus(e); if (AutoSelectAllOnGotFocus) { _passwordBoxControl.SelectAll(); } }
private void PasswordInput_GotFocus(object sender, RoutedEventArgs e) { PasswordBox expr_06 = sender as PasswordBox; if (expr_06 == null) { return; } expr_06.SelectAll(); }
public static void bindTextBox(PasswordBox passwordBox, string name) { passwordBox.Password = settings[name] as string; passwordBox.PasswordChanged += (sender, e) => { settings[name] = passwordBox.Password; }; passwordBox.GotFocus += (sender, e) => { passwordBox.SelectAll(); }; }
public LoginViewmodel(IView view) { Properties.Settings settings = new Properties.Settings(); EmailAdress = settings.LastUsername; ServiceResolver.GetContainer().Register <IUserProvider, DesktopUserProvider>(Lifestyle.Singleton); LoginTaskNotifier = new NotifyTaskCompletion <LoginResult>(Task.FromResult <LoginResult>(null)); RegisterTaskNotifier = new NotifyTaskCompletion <RegisterResult>(Task.FromResult <RegisterResult>(null)); _view = view; CloseCommand = new RelayCommand((object obj) => { Environment.Exit(0); }); LoginCommand = new RelayCommand((object obj) => { PasswordBox passBox = obj as PasswordBox; if (!string.IsNullOrWhiteSpace(EmailAdress) && !string.IsNullOrWhiteSpace(passBox.Password)) { passBox.SelectAll(); StartLogin(EmailAdress, passBox.Password); } }); RegisterCommand = new RelayCommand((object obj) => { if (IsRegistering && !string.IsNullOrWhiteSpace(EmailAdress)) { var loginView = obj as LoginView; ErrorMessage = string.Empty; if (loginView.PassBoxReg1.Password != loginView.PassBoxReg2.Password) { ErrorMessage = "Wachtwoorden komen niet overeen"; } if (ErrorMessage == string.Empty) { lastPassword = loginView.PassBoxReg1.Password; RegisterTaskNotifier = new NotifyTaskCompletion <RegisterResult>(LoginRepository.Instance.Register(EmailAdress, loginView.PassBoxReg1.Password), CompletedRegistration); } } else { IsRegistering = true; } }); CancelRegisterCommand = new RelayCommand((object obj) => { IsRegistering = false; }); }
public static void FocusAndSelect(this PasswordBox passwordBox) { if (passwordBox != null) { if (!passwordBox.IsFocused) { passwordBox.Focus(); } passwordBox.SelectAll(); } }
private bool IsValid(PasswordBox passwordBox, string propertyDisplayName, string value) { if (string.IsNullOrWhiteSpace(value)) { MessageBox.Show(propertyDisplayName + " can't be empty.", Title); passwordBox.Focus(); passwordBox.SelectAll(); return(false); } return(true); }
bool checkSetting(bool result, PasswordBox passwordBox, string message) { if (!result) { MessageBox.Show(message, resources["Connect"] as string, MessageBoxButton.OK, MessageBoxImage.Warning); passwordBox.SelectAll(); passwordBox.Focus(); } return(result); }
public void SelectAll() { if (VisiblePassword) { _textBox?.SelectAll(); } else { _passwordBox?.SelectAll(); } }
private static void TrySet(PasswordBox textBox, bool value) { if (value) { textBox.GotKeyboardFocus += async(s, a) => { await Task.Delay(20).ConfigureAwait(true); // Quite ugly but required to make it work textBox.SelectAll(); }; } }
private string ValidateInput(PasswordBox box, string boxName) { string user = box.Password; if (string.IsNullOrEmpty(user)) { MessageBoxEx.Show(string.Format("Please provide non-empty {0}", boxName), "Error", MessageBoxButton.OK, MessageBoxImage.Error); box.Focus(); box.SelectAll(); return(null); } return(box.Password); }
/// <summary> /// Occurs when this FrameworkElement is initialized. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="eventArgs">An EventArgs that contains no event data.</param> void OnPasswordBoxInitialized(Object sender, EventArgs eventArgs) { // Since we don't have access to the password (as it is secured inside the SecureString object), we will fill in the password box with a dummy set of // characters that is the same length as the password. Since the box encodes the characters anyway, it doesn't 'really matter what we initialize the // box with so long as it has the proper number of characters. PasswordBox passwordBox = sender as PasswordBox; DomainCredential domainCredentials = passwordBox.DataContext as DomainCredential; passwordBox.Password = new String('*', domainCredentials.SecurePassword.Length); // We assume that all passwords are going to be overwritten since we can't really edit them like a visible string. passwordBox.SelectAll(); }
private void RegisterButton_Click(object sender, RoutedEventArgs e) { string username = UsernameBox.Text; string password = HashAndSalt(PasswordBox.Password); if (username.Length == 0 && PasswordBox.Password.Length == 0) { ErrorText.Text = "To register, type a username and password in the boxes above."; UsernameBox.SelectAll(); UsernameBox.Focus(); } else if (username.Length == 0) { ErrorText.Text = "Username cannot be blank."; UsernameBox.SelectAll(); UsernameBox.Focus(); } else if (PasswordBox.Password.Length < 8) { ErrorText.Text = "Password must be at least 8 characters."; PasswordBox.SelectAll(); PasswordBox.Focus(); } else if (!(new Regex(@"^[a-zA-Z0-9]*$").IsMatch(username))) { ErrorText.Text = "Usernames must be alphanumeric."; UsernameBox.SelectAll(); UsernameBox.Focus(); } else { var addUserResult = Operations.Insert( string.Format( "INSERT INTO users(username, password) VALUES (\"{0}\", \"{1}\");", username, password)); int code = addUserResult; if (code == 0) { ErrorText.Text = "Registration successful! Please login to access application."; } else if (code == 1062) { ErrorText.Text = "Username taken."; } else { ErrorText.Text = "Error registering user. (" + code + ")"; } } }
private void DoCredentialsFocussed(object sender, RoutedEventArgs e) { TextBoxBase tb = sender as TextBoxBase; if (tb == null) { PasswordBox pwb = sender as PasswordBox; pwb.SelectAll(); } else { tb.SelectAll(); } }
private void SetSelection(PasswordBox passwordBox, int start, int length) { try { if (start < 0x0) { start = passwordBox.Password.Length; } passwordBox.GetType().GetMethod("Select", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(passwordBox, new object[] { start, length }); } catch (Exception exception) { DebugLog.Assert(false, exception.Message); passwordBox.SelectAll(); } }
public void SetText(string text) { _internalTextChange = true; if (_usePasswordBox) { _passwordBox.Password = text; _passwordBox.SelectAll(); } else { _textBox.Text = text; _textBox.Select(text.Length, 0); } _internalTextChange = false; }
public void SetText(string text) { Deployment.Current.Dispatcher.BeginInvoke(() => { _internalTextChange = true; if (_password) { _passwordField.Password = text; _passwordField.SelectAll(); } else { _textField.Text = text; _textField.Select(text.Length, 0); } _internalTextChange = false; }); }
private static void OnGotFocus(object sender, RoutedEventArgs e) { TextBox textBox = FocusManager.GetFocusedElement() as TextBox; if (textBox != null && !(bool)textBox.GetValue(AttachedProperties.PreventAutoSelectTextProperty)) { textBox.SelectAll(); } else { PasswordBox passwordBox = FocusManager.GetFocusedElement() as PasswordBox; if (passwordBox == null || (bool)passwordBox.GetValue(AttachedProperties.PreventAutoSelectTextProperty)) { return; } passwordBox.SelectAll(); } }