我使用以下函数getPass()来输入安全密码:
def getPass():
password = ''
while True:
x = getch.getch()
# x = msvcrt.getch().decode("utf-8")
if x == '\r' or x == '\n':
break
print('*', end='', flush=True)
password += x
return password但是,有一个问题是,除了作为新字符外,不接受后置空间:
现实生活中的后置空间是这样出现的:(用作参考的符号)
在此之前:
···
之后:
···
但是当我执行getpass()时,它会出现在控制台中,如下所示:
以前:****|
然后你撞到了后面,你会变成什么样子
*** |
实际上成了
****|*
(注意额外的星星)。
也许我应该把这个解决方案留在print('Type your password:\n(Backspace not accepted: Press Enter to redo))中,把用户放在一个循环中,但是这对21世纪的用户来说是非常烦人的。
发布于 2021-02-08 21:56:38
我可以使用标准的getpass()模块。
from getpass import getpass
def getPass():
password = getpass.getpass('Enter Your Password\n>>>')
return password
password = getpass()https://stackoverflow.com/questions/66109953
复制相似问题