你知道如何在Linux中尝试一些Sudo的东西它会告诉你输入密码,当你输入时,终端窗口中没有显示任何内容(密码没有显示)?
有没有办法在Python中做到这一点?我正在编写一个需要如此敏感信息的脚本,并希望在我输入时隐藏它.
换句话说,我想从用户那里获取密码而不显示密码.
当我运行此代码时:
import getpass
p = getpass.getpass(prompt='digite a senha\n')
if p == '12345':
print('YO Paul')
else:
print('BRHHH')
print('O seu input foi:', p) # p = seu input
Run Code Online (Sandbox Code Playgroud)
我收到了这个警告:
Warning (from warnings module):
File "/usr/lib/python3.4/getpass.py", line 63
passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed.
Run Code Online (Sandbox Code Playgroud)