Uh oh!
There was an error while loading. Please reload this page.
gh-138514: getpass: restrict echo_char to a single ASCII character - #138591
Conversation
echo_char to a single ASCII characterUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bkjoh
commented
Sep 6, 2025
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>
Uh oh!
There was an error while loading. Please reload this page.
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 |
picnixz
commented
Sep 10, 2025
Does it also happen when there is no echo char? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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]*.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 |
picnixz
commented
Sep 11, 2025
I think they are interpreted that way because on Unix we use termios while on Windows it's provided by |
picnixz
commented
Sep 11, 2025
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 |
bkjoh
commented
Sep 15, 2025
@picnixz would you like me to make any additional modifications? |
picnixz
commented
Sep 15, 2025
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. |
Fixesgh-138514.
📚 Documentation preview 📚: https://cpython-previews--138591.org.readthedocs.build/