Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何替换用户的每个字符';s输入,在空闲终端中带有星号(****)_Python_Python 3.x_Passwords - Fatal编程技术网

Python 如何替换用户的每个字符';s输入,在空闲终端中带有星号(****)

Python 如何替换用户的每个字符';s输入,在空闲终端中带有星号(****),python,python-3.x,passwords,Python,Python 3.x,Passwords,出于安全原因,我试图在空闲终端中将用户输入的每个字符替换为星号(*),因为用户将输入密码。我已经找到了一些替代方法,比如getpass()模块,但是getpass()不会在终端空闲时显示任何内容来告诉用户他/她正在键入。因此,我决定寻找替代解决方案,而不是getpass() 我写了这段代码,它为我完成了任务 只需通过getch()将用户的输入作为一系列字符 不是打印输出,而是在每次输入后打印* def check_password(x): while x != ("admin123"):

出于安全原因,我试图在空闲终端中将用户输入的每个字符替换为星号(*),因为用户将输入密码。我已经找到了一些替代方法,比如getpass()模块,但是getpass()不会在终端空闲时显示任何内容来告诉用户他/她正在键入。因此,我决定寻找替代解决方案,而不是getpass()

我写了这段代码,它为我完成了任务

只需通过getch()将用户的输入作为一系列字符

不是打印输出,而是在每次输入后打印*

def check_password(x):
while x != ("admin123"):
    x = input("incorrect password \ntry again:")
return x

password = input("please type the password: ")
password = check_password(password)
print ("correct password")

我写了这段代码,它为我完成了任务

只需通过getch()将用户的输入作为一系列字符

不是打印输出,而是在每次输入后打印*

def check_password(x):
while x != ("admin123"):
    x = input("incorrect password \ntry again:")
return x

password = input("please type the password: ")
password = check_password(password)
print ("correct password")

可能重复的@Gary解决方案对我不起作用,因为我在windows上使用空闲,它显示(没有名为“termios”的模块),因此这不是我问题的解决方案。@Y.Hasan通过谷歌搜索找到了我。也许这会有帮助。是的,有时这种重复标记会杀死实际的非重复问题
:-(
可能重复的@Gary解决方案对我不起作用,因为我在windows上使用空闲,它显示(没有名为“termios”的模块),所以这不是我问题的解决方案。@Y.Hasan通过谷歌搜索找到了我。这可能会有所帮助。是的,有时候这种重复标记的东西会杀死实际的非重复问题
:-(