gh-138514: getpass: restrict echo_char to a single ASCII character#138591
gh-138514: getpass: restrict echo_char to a single ASCII character#138591picnixz merged 32 commits intopython:mainfrom bkjoh:gh-138514-fix-getpass-echo-char
echo_char to a single ASCII character#138591Conversation
echo_char to a single ASCII character
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 <10796600+picnixz@users.noreply.github.com>
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 <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
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. |
picnixz
left a comment
There was a problem hiding this comment.
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 <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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 <benjohnson2040@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
|
GH-138988 is a backport of this pull request to the 3.14 branch. |
Fixes gh-138514.
📚 Documentation preview 📚: https://cpython-previews--138591.org.readthedocs.build/