Hide password during typing with a new prompt input#1962
Hide password during typing with a new prompt input#1962Crissal1995 wants to merge 9 commits intoprompt-toolkit:mainfrom
Conversation
New input added to the prompt(): hide_password False by default, if True, the characters won't be echoed back (as *) in the output
| When True (the default), automatically wrap long lines instead of | ||
| scrolling horizontally. | ||
| :param is_password: Show asterisks instead of the actual typed characters. | ||
| :param hide_password: Hide the password, rather than showing asterisks. |
There was a problem hiding this comment.
Would it make sense to accept password_character here instead of hide_password? It will be more flexible.
There was a problem hiding this comment.
Undoubtedly, but from an user perspective hide_password is more clear.
Besides, is there any valuable use-case where the password is displayed as something else, e.g. xxxxx or 11111?
There was a problem hiding this comment.
I can imagine that some might want to render it as Unicode bullets, because that's more beautiful.
Like password_character="•"
I mainly want to avoid having too many redundant arguments here. We have to repeat them in multiple places and the signature gets pretty long. If at some point, some users want to configure this, we'll have both hide_password and password_character.
Honestly, I'm not sure myself. If there was some prior art in other libraries, that could convince me to go one way or another.
There was a problem hiding this comment.
An alternative would be to use both flags, forcing password_character to be an empty string if hide_password is True.
In this way users could either use the flag hide_password if they don't care about how the password is displayed on screen, or the flag password_character if they want to customize the appearance, as youy suggested.
|
Apparently running the tests with EDIT: Found an unrelated bug related to the |
This PR resolves #1783.
The
PasswordProcessorby default (current implementation, no argument given) outputs a*for each letter typed by the user in the prompt.However, the desired behavior would be to make the typed password invisible, e.g. like
getpassdoes.Two tests were added, and the example was also modified and tested locally to make sure that the change works as intended.