5

目前我正在制作一个图像身份验证项目,其中我需要借助密钥对图像进行身份验证。我raw_input通过 IPython 控制台从用户那里获取密钥。我想隐藏正在输入的密钥。

预期结果:

Enter the key = *****或者Enter the key = (nothing shown)

我找到getpass()了隐藏输入数据的方法,但它在我的电脑上给出了以下警告: Warning: QtConsole does not support password mode, the text you type will be visible.

我什至看到了这段代码:

import sys
import msvcrt

passwor = ''
while True:
    x = msvcrt.getch()
    if x == '\r':
        break
    sys.stdout.write('*')
    passwor +=x

print '\n'+passwor

但这会在显示屏上打印无限数量的星号。

请让我知道这个问题的一些解决方案。

4

0 回答 0