Bugs item #1233785, was opened at 2005-07-07 09:36 Message generated for change (Comment added) made by esrever_otua You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1233785&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Darryl Dixon (esrever_otua) Assigned to: Nobody/Anonymous (nobody) Summary: getpass.getpass() performs differently on Windows vs *nix Initial Comment: getpass.getpass() on *nix platforms allows users to input unicode characters and other NLS input. getpass.getpass() on Windows only allows ASCII input in the 0-127 codepage range. This means that getpass can not be used cross-platform for complex passwords. ---------------------------------------------------------------------- >Comment By: Darryl Dixon (esrever_otua) Date: 2005-07-07 22:42 Message: Logged In: YES user_id=567623 I am not an expert C coder (no surprise) however this simple code I wrote will accept a line of input (including the \r\n on the end) without echoing it back to the user: #include <windows.h> #define LINE_BUF 65536 char *getstr(){ /* * OK, basically, we get a handle to STDIN, take a copy of the * flags currently in force, set our own to prevent screen echo, * do a read of the console that returns on '\r\n' (included in * returned string), restore the original flags on STDIN, and * finally returns the input string. * * This is basically a re-implementation of getch(), but instead * of a single char, you get a whole string (with no screen echo). * * For docs on functions called, see: * http://msdn.microsoft.com/library/en-us/dllproc/base/console_functions.asp */ HANDLE hstdin; DWORD read_chars, mode; char in_chars[LINE_BUF]; hstdin = GetStdHandle(STD_INPUT_HANDLE); GetConsoleMode(hstdin, &mode); SetConsoleMode(hstdin, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); ReadConsole(hstdin, in_chars, LINE_BUF, &read_chars, NULL); SetConsoleMode(hstdin, mode); return in_chars; } This code, when SWIG-ed to use with Python 2.4.1 works perfectly. The key is setting the flags on the console handle to remove the ENABLE_ECHO_INPUT flag. Also, if ENABLE_LINE_INPUT is removed, theoretically the ReadConsole() function should return after each typed character. On *nix you can use unicode_start and loadkeys to input unicode directly, including ALT+xxxx style input. Regards, D ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-07-07 22:29 Message: Logged In: YES user_id=1188172 Okay. This isn't menat to attempt a flamewar, but rather find out what can be done to help you (and, thank you very much for making it simple extra for me, I would have preferred the simple version even if I was a native speaker). You're right that this bug report is about getpass's portability, I had a bit lost track of this. Since you posted the link to your tracker in your previous comment, I somehow linked this to here. I have only two questions left. 1) Do you know another function in the MS API that allows reading a character from the console without displaying it? 2) How do you input your characters under the sun on Unix? Can you do this on a text console, too? ---------------------------------------------------------------------- Comment By: Darryl Dixon (esrever_otua) Date: 2005-07-07 22:15 Message: Logged In: YES user_id=567623 Right. I've had enough of this nonsense, listen carefully: as English isn't your first language I'll make this as simple as possible: 1) I didn't come here to start a flame war, but rather to point out a genuine deficiency in the Windows getpass, compared to the *nix version. 2) You didn't lie, and *I didn't accuse you of that*, but rather pointed out that all was not correct or complete in your assertion. *I* was right, as you carefully neglected to mention that you're using a native keyboard, with an NLS system that puts ü below ASCII 127 in your local codepage 3) getpass.getpass(), when called on *nix, allows me to input '¿' and every other character under the sun. When called on Windows, *it does not*. This Means Complex Passwords With getpass() Aren't Portable. End Of Story. It Is Undocumented. This Is A Bug. 4) Yes the problem isn't that getch() isn't doing what it should, it is that getch() is the *wrong function to use* in order to gain parity with the *nix version. 5) Finally, you seem hell-bent on ignoring what I've written. I was wrong about getch() behaviour on python-dev, but That Isn't The Problem, which is why *I* didn't mention it in this initial bug-report. My assertion below that getch() won't get anything above ASCII 255 is *completely accurate*. It is the Wrong Function To Use. This Is A Bug In Getpass. 6) Finally, Finally, please read this and understand: As per the initial bug-report, the problem is that getpass on Windows is limited in ways that getpass on *nix isn't. ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-07-07 22:01 Message: Logged In: YES user_id=1188172 First of all, don't accuse me of lying. If I wanted to lie professionally, I would have become politician, not programmer. I'm German, and using a German keyboard layout which does have the ü, so it can be perfectly input. Your problem is that you cannot input characters which don't directly create keycodes on the keyboard, but must be copied to the console in some way. In python-dev, you said that msvcrt.getch() would have to call _getch() a second time in the case that it returns 0x00 or 0xe0 the first time and/or return a Unicode string. First, the documentation for _getch() says that this is a special case for arrow and function keys (such as F1 or <Up>). These keys don't have a representation in any character set, as they are control keys, so how would you represent them as Unicode? Second: In my console, pressing F7 yields the return values "\x00" and "A". When the 0x00/0xe0 read the first time is secretly swallowed, the user of msvcrt.getch() can't know whether the user pressed "A" or F7. That said, the behaviour of getch() is documented and correct. But how does that all help you with your original problem, which is that _getch() doesn't help you with Alt+XXXX sequences or console window Copy-Paste? In my understanding _getch() only works with characters directly input to the console. Sorry, but then this is not a Python problem but a Windows one. ---------------------------------------------------------------------- Comment By: Darryl Dixon (esrever_otua) Date: 2005-07-07 21:18 Message: Logged In: YES user_id=567623 I think that, because I've read the source, and getpass.getpass() uses msvcrt.getch() on Windows, which doesn't support anything at all above ASCII 255. Also because I have a bug report pending against one of the projects that I maintain from a user that is experiencing a problem because of exactly this issue. See: https://sourceforge.net/tracker/index.php?func=detail&aid=1224877&group_id=69259&atid=523935 Also, I call shenanigans on your claim of successfully inputting an umlaut-u into getpass.getpass(); this character can *theoretically* be input, as it's below ASCII 255, but in practice I can neither input it directly, nor COPY+PASTE it from the clipboard on my WinXP SP2 with Python 2.4.1 installed. Finally, regardless of whether "ü" works or not, other characters that live solely in unicode, such as "¿" most certainly do not (and never will) work (not even theoretically). Regards, D ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-07-07 20:46 Message: Logged In: YES user_id=1188172 What makes you think that? I tried it on Windows XP, in a cmd.exe session. I could enter, for example, an ü (umlauted u), which in the resulting string came out encoded as \x81, as is correct in the encoding used by the console window, namely cp850. I could then convert this to latin1 by using s.decode(sys.stdin.encoding).encode("latin-1"). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1233785&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com