6

In my application there is a TEdit with PasswordChar = '*'.

When the user presses Ctrl + C a hint appears.

Screenshot of a Windows edit control in password mode showing its "cannot copy" balloon.

Translated:

Not Allowed

You cannot copy text from a password field.

And obviously, the Copy item in the drop-down menu is disabled

Screenshot of a Windows edit control in password mode with its context menu visible; the Copy item is disabled.

Is there a way to enable the copy action for password editors?

Fred
  • 3,365
  • 4
  • 36
  • 57
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • 2
    Obviously this is by design. The TEdit is a Windows common control. Either write your own control or do what Uwe says. There are good reasons for this behavior. – kobik Feb 27 '20 at 08:46
  • 2
    @Fabrizio: Please remember to replace the "Enter image description here" texts with proper summaries of what the images contain. Otherwise, visually impaired people, using screen readers, will not be able to understand your Q. Also, Google will find it more difficult to understand the content of the images. I changed the ALT texts to "Screenshot of a Windows edit control in password mode showing its "cannot copy" balloon." and "Screenshot of a Windows edit control in password mode with its context menu visible; the Copy item is disabled.", respectively. Notice that they do describe the images. – Andreas Rejbrand Feb 27 '20 at 09:16
  • 2
    (Otherwise, your question is very beautifully formatted!) – Andreas Rejbrand Feb 27 '20 at 09:25
  • @AndreasRejbrand: Thank you! I always forget to add the picture descriptions, next time I'll try to do better :) – Fabrizio Feb 27 '20 at 09:41

2 Answers2

9

The usual way is to have a button right to the edit field allowing to display the password. This may be bound to some access conditions. While the password is visible it can be copied as well.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
7

This is just a minor extension to Uwe Raabe's correct answer; please prefer to upvote/accept his answer.

You could actually choose to have two buttons next to the password edit control1:

  • One that displays the password on-screen (that is, sets PasswordChar = #0). This can be made either temporarily while the button is being depressed, or it can toggle between the two states on each click. (If you choose the first method, remember that the UI has to be 100% usable without a mouse, only using the keyboard.)
  • One that copies the password to clipboard.

Screenshot of a Windows password edit control with two small buttons next to it to the right. The first small button has a glyph resembling an eye; the second small button has a copy icon glyph.

Firefox offers this dual functionality, and I find it very convenient to be able to put the password in clipboard without it ever been visible on-screen.

Optionally, you may require some security check before any of the actions. For instance, Firefox asks for the master password (if present).

1 Make sure both buttons can be used both with the mouse and with the keyboard. In particular, this means that you cannot use TSpeedButton controls (at least not without additional effort). TBitBtn is OK, though. Also make sure the tab order is correct: from left to right. It is a good idea to create a new custom control with this three-control constellation. I'd advice you to let the buttons have tooltips: Show password and Copy password, respectively.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384