This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, matejcik, paul.moore, steve.dower, terry.reedy, tim.golden, zach.ware
Date 2021-08-05.13:22:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628169760.98.0.404138205954.issue44762@roundup.psfhosted.org>
In-reply-to
Content
The `sys.stdin is not sys.__stdin__` check is not relevant information. We need to know whether msvcrt.getwch() works and that the user should be able to type the password in the console window. sys.__stdin__ could be a file object for the NUL device, a pipe, or a file.

Also, this check has never been implemented in POSIX. If I run `python -m idlelib` in Linux, getpass() still reads the password from the terminal instead of sys.stdin.

> IDLE's stdio connected to Shell passes isatty

IOBase.isatty() is more abstract than I expected, since it can be true for any stream that's "interactive". While FileIO.isatty() and os.isatty() are definitely wrong in Windows (i.e. they should not be true for NUL or a serial/parallel port), I see now that fixing isatty() doesn't solve the problem. 

We need to directly check whether sys.stdin is a console. If so, we can reasonably assume that there's a visible, accessible console window. The check would be something like:

    try:
        _winapi.GetConsoleMode(msvcrt.get_osfhandle(sys.stdin.fileno()))
    except (AttributeError, OSError):
        return fallback_getpass(prompt, stream)

_winapi.GetConsoleMode() would need to be implemented.

This is inconsistent with Unix since it's not trying to open "CONIN$". But relying on the latter is problematic in Windows since it succeeds in any process that's attached to a console session, even if the console window is hidden or never created (i.e. CREATE_NO_WINDOW).
History
Date User Action Args
2021-08-05 13:22:41eryksunsetrecipients: + eryksun, terry.reedy, paul.moore, tim.golden, matejcik, zach.ware, steve.dower
2021-08-05 13:22:40eryksunsetmessageid: <1628169760.98.0.404138205954.issue44762@roundup.psfhosted.org>
2021-08-05 13:22:40eryksunlinkissue44762 messages
2021-08-05 13:22:40eryksuncreate