-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-138514: getpass: restrict echo_char
to a single ASCII character
#138591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-138514: getpass: restrict echo_char
to a single ASCII character
#138591
Conversation
echo_char
to a single ASCII character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests?
Misc/NEWS.d/next/Library/2025-09-06-11-26-21.gh-issue-138514.66ltOb.rst
Outdated
Show resolved
Hide resolved
Yes! Thank you for the feedback and review. I intended to work on this some more. I will add tests and look for potential efficiencies made possible by no longer accepting multi-character strings. |
Co-authored-by: Bénédikt Tran <[email protected]>
Misc/NEWS.d/next/Library/2025-09-06-11-26-21.gh-issue-138514.66ltOb.rst
Outdated
Show resolved
Hide resolved
Note that we have 3.14-rc3 coming next week so I would like for this to be merged before if possible. If you don't have enough time, I can take over. |
I can do this now! I apologize for the delay. |
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Brian Schubert <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
I notice on Windows when an arrow key is used during password entering, two |
Does it also happen when there is no echo char? |
I don't think it's an "issue". When I use sudo to enter my password and press left/right arrows, they are not interpreted as left/right arrows. It could be considered a feature if you think it's worth it but OTOH, I think it'll be too complex and really too niche. If the password is wrong, or if made a typo, you usually erase using backspace or re-enter the password. Should this feature be supported, a preliminary thread in https://discuss.python.org/c/ideas/6 shouold be opened. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the s
to rejects and just use reject
. It saves 1 char and we usually have test_[verb]*
instead of test_[conjugated form]*
.
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
However, left/right arrows currently are being interpreted as left/right arrows in a way, right (since arrow keys are recorded as bytes/characters)? Instead of supporting this behavior, could we more simply remove it? |
I removed the |
I think they are interpreted that way because on Unix we use termios while on Windows it's provided by |
Unless there is a conflict to solve or a CI test to fix (that your changes wouldn't affect), avoid merging main into your branch as it wastes CI resources. TiA! |
Because I |
Mmh, no. If we say "we expect a string", and you give something that is not a string, usually it raises a TypeError or an AttributeError. Currently passing something like |
@picnixz would you like me to make any additional modifications? |
I'll take a look tomorrow during the sprint! |
Thanks @benjaminjohnson01 for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…acter (pythonGH-138591) This amends commit bf8bbe9 by restricting `echo_char` in `getpass.getpass` to single printable ASCII characters as it would be uncommon to use long strings or multi-byte characters for keyboard feedback. --------- (cherry picked from commit ab6893a) Co-authored-by: Benjamin Johnson <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Brian Schubert <[email protected]>
GH-138988 is a backport of this pull request to the 3.14 branch. |
…racter (GH-138591) (#138988) Co-authored-by: Benjamin Johnson <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Brian Schubert <[email protected]>
Fixes gh-138514.
📚 Documentation preview 📚: https://cpython-previews--138591.org.readthedocs.build/