如何在python中使用getpass模块输入密码时获得星号?
实际结果:
import getpass
p=getpass.getpass("Enter the Password:")
Enter the Password:
print (p)
Output: password
Run Code Online (Sandbox Code Playgroud)
期待结果:
import getpass
p=getpass.getpass("Enter the Password:")
Enter the Password:********
print (p)
Output: password
Run Code Online (Sandbox Code Playgroud)
Python 版本:2.7
我想写一个小项目,它需要你输入你的id和passwd,但我需要一个函数来在输入passwd时用'*'替换passwd,我只知道raw_input()可以输入一些东西,所以我不能解决这个问题.怎么写这个功能?
我正在使用 Python 3.7,我需要import termios屏蔽密码输入。但我无法在https://pypi.org/上找到它
import sys, tty, termios
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sys, tty, termios
File "C:\Python37\lib\tty.py", line 5, in <module>
from termios import *
ModuleNotFoundError: No module named 'termios'
Run Code Online (Sandbox Code Playgroud) 有没有办法通过回显星号来保护用户输入?
或者我需要看一个不同的方法,并使用输入()之外的东西.
似乎草率地让用户输入他们的凭证而没有一些基本的保护或考虑.
使用getpass时,我无法对gmail进行身份验证.
使用pass = getpass.getpass('输入密码')是否需要进行其他考虑或"解包"?
我需要为输入密码编写代码,就像当我需要输入密码时,它需要像这样*****一样对密码进行分层。请注意,我使用PyCharm进行编码。

我一直在尝试在我一直在开发的 python 程序上进行安全登录,但我尝试的一切似乎都没有帮助。我需要一段可以放入脚本中的代码片段。我的主要问题是任何查看我的脚本的人都只能看到密码。另外,我不知道在输入密码时如何输入星号而不是字符。这是我的登录代码,它非常基本,因为我几乎是初学者。
#login
import webbrowser as w
def username():
print("Enter UserName")
usrnm = input()
if(usrnm == "example"):
password()
else:
notusername()
def notusername():
print("Try Again")
username()
def password():
print("Enter Password")
pswrd = input()
if(pswrd == "password"):
w.open("www.example.net")
else:
notusername()
username()
Run Code Online (Sandbox Code Playgroud) 有没有办法让python输入密码???
代替:
Whats your password?
password <--- this is a user input
Run Code Online (Sandbox Code Playgroud)
我需要:
Whats your password?
******** <--- this is a user input
Run Code Online (Sandbox Code Playgroud)
这在Python中可能吗?
我正在创建一个程序,要求用户输入密码.有没有一个代码可以添加到我的程序中,如果有人坐在用户后面或者看着他/她的肩膀他们没有在屏幕上看到密码?
python ×7
python-2.7 ×2
passwords ×1
pycharm ×1
python-3.5 ×1
python-3.7 ×1
security ×1
termios ×1