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 W_M
Recipients Atul Bagga, W_M, brianhrutledge, docs@python, eryksun, paul.moore, steve.dower, terry.reedy, tim.golden, zach.ware
Date 2022-02-25.14:04:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645797869.99.0.925598829168.issue37426@roundup.psfhosted.org>
In-reply-to
Content
I have an idea to solve it. But I don't know how to get the clipboard data.

The code like this (Windows):

def win_getpass(prompt='Password: ', stream=None, echoChar='*'):
    """Prompt for password with echo off, using Windows getwch()."""
    if not isinstance(echoChar, str) or len(echoChar) < 1 or len(echoChar) > 1:
        raise ValueError("Argument 'echoChar' is incorrect. It should be a character.")
    if sys.stdin is not sys.__stdin__:
        return fallback_getpass(prompt, stream)
    for c in prompt:
        msvcrt.putwch(c)
    pw = ""
    while 1:
        c = msvcrt.getwch()
        if ord(c) == 22: # User pressed Ctrl-V
            k = <Clipboard Info>
            pw += k
            for _ in range(len(k)):
                msvcrt.putwch(echoChar)
        if c == '\r' or c == '\n' or c == '\r\n':
            break
        if c == '\003':
            raise KeyboardInterrupt
        if c == '\b':
            if pw != '':
                pw = pw[:-1]
                count = len(pw)
                for _ in range(count+1):
                    msvcrt.putwch('\b')
                for _ in range(count):
                    msvcrt.putwch(echoChar)
                msvcrt.putwch(' ')
                msvcrt.putwch('\b')
        else:
            pw = pw + c
            msvcrt.putwch(echoChar)
            
    msvcrt.putwch('\r')
    msvcrt.putwch('\n')
    return pw
History
Date User Action Args
2022-02-25 14:04:30W_Msetrecipients: + W_M, terry.reedy, paul.moore, tim.golden, docs@python, zach.ware, eryksun, steve.dower, Atul Bagga, brianhrutledge
2022-02-25 14:04:29W_Msetmessageid: <1645797869.99.0.925598829168.issue37426@roundup.psfhosted.org>
2022-02-25 14:04:29W_Mlinkissue37426 messages
2022-02-25 14:04:29W_Mcreate