2

The following code snippet:

from getpass import getpass

username = input("Username: ")
password = getpass("Password: ")

When run in Visual Studio Code's integrated Python Console produces the following result:

Username: User
Warning: Password input may be echoed.
Password: hunter2

So whatever I type after the password prompts gets shown. Is there any way to hide this in the integrated VS Code Terminal? In a normal command prompt for example when running

python test.py

I get the following output:

Username: User
Password:

So as expected, whatever I type here after the password prompt does not get displayed.

Matthias
  • 12,704
  • 13
  • 35
  • 56
  • Perhaps this might point you towards a solution: https://github.com/microsoft/ptvsd/issues/1723 (the issue was closed though, so it should have been solved...) – GPhilo Oct 22 '19 at 12:40
  • What is your OS? Because the [referenced Github issue](https://github.com/microsoft/ptvsd/issues/1723) says it was already fixed on Windows and I cannot replicate the issue on Linux and on Mac. – Gino Mempin Oct 22 '19 at 13:38
  • Windows 10. I see that the Github says it's closed but I can reproduce it exactly as described there. – Matthias Oct 22 '19 at 13:39
  • Well, I think you'll need to reopen that ticket or create a new one, because it's a VS code issue. I don't agree with the duplicate because switching over to an external terminal/console isn't really a solution. – Gino Mempin Oct 22 '19 at 13:50
  • @GinoMempin from the [documentation](https://docs.python.org/3/library/getpass.html): *If echo free input is unavailable `getpass()` falls back to printing a warning message to stream and reading from `sys.stdin` and issuing a `GetPassWarning`.* As it highly depends on the console being worked on, this is not an issue that is easily sidestepped and thus why the fallback to a echo-free console would be my recommendation. Anything else would entail a deeper dive, and you might as well not be using `getpass` IMO. – r.ook Oct 22 '19 at 14:28
  • 1
    Also you need to consider the use case here - if this script is to be used regularly for password inputs, why isn't it executed independent of VS Code? Are users expected to always use VS Code to execute the script? The IDE should only be used for developing/debugging, that'd be my opinion at least. Once you put that in perspective this is not an issue at all. – r.ook Oct 22 '19 at 14:34
  • @r.ook OK, I understand your point and I get that it is an expected behavior of `getpass`. I was just under the impression that the question was _how to have the same behavior on VS Code_, which from the referenced Github issue, they were (supposedly) already able to do before on Windows. That's why I said it should be raised again to VS Code devs. As for the use-case, yes it's for dev/debugging only, given that we are talking about VS Code, it is a use-case that as a developer, I would want my dev env to behave the same way as the live env (which on Linux and Mac, VS Code can). – Gino Mempin Oct 23 '19 at 00:25
  • I guess the real answer is this: It is a bug in VS Code, and it will be fixed in the next release of ptvsd. Version v5.0.0a6: https://github.com/microsoft/ptvsd/commit/90298c4e7903513e53b86bc670be9fdfe8754be3 – Matthias Oct 23 '19 at 05:54

0 Answers0