使用 getpass.getpass() 在 python 中隐藏密码

Hide password in python using getpass.getpass()

当我输入时

>>> passwd = getpass.getpass()

进入python 2.7 shell,在IDLE中,我得到的结果是:

Warning (from warnings module):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 55
    passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Password:

然后当我输入密码时,它不会被隐藏。我需要将它发送到一个变量,所以我可以使用 sha 模块对它进行 SHA,并将它与 'SHAed' 原始文件进行比较。

pass 是 python 关键字。请更改为

password = getpass.getpass()

然后 运行 它来自 shell/console