This project is read-only.

PasswordInputPrompt throws ArgumentOutOfRangeException when pasting chars to password field

Apr 23, 2013 at 12:40 PM
The PasswordInputPrompt only works when typing in the password chars one by one. If you try to paste a password stored in clipboard you get ArgumentOutOfRangeException .

A fix would be to change the following lines:

Line 56:
var selectionIndex = selectionStart - 1;
var selectionIndex = selectionStart - diff;
Line 64:
replacementString.Insert(0, PasswordChar.ToString(CultureInfo.InvariantCulture), InputBox.Text.Length - 1);
replacementString.Insert(0, PasswordChar.ToString(CultureInfo.InvariantCulture), InputBox.Text.Length - diff);
Or even better, to make the control act as the default PasswordBox is to have the pasted chars immediately show as * without the delayed overwrite. Something like this:
      } else if (diff > 0) {
          if (diff > 1) { // Paste operation
              var tempSelectionStart = InputBox.SelectionStart;
              var pasteIndex = InputBox.SelectionStart - diff;
              var pastedChars = InputBox.Text.Substring(pasteIndex, diff);
              _inputText.Insert(pasteIndex, pastedChars);
              var replacementString = new StringBuilder();
              replacementString.Insert(0, PasswordChar.ToString(CultureInfo.InvariantCulture), InputBox.Text.Length);
              InputBox.Text = replacementString.ToString();
              InputBox.SelectionStart = tempSelectionStart;
              Value = _inputText.ToString();

          // get new chars
          // append onto SB
          // set value
          // update InputBox with *
Apr 23, 2013 at 5:39 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 27, 2013 at 7:52 PM
Fixed in 79138, refactored suggested fix to reduce repeating of code. good catch and thanks for helping with the fix.