如何隐藏密码字符? [英] How to hide password characters?

查看:63
本文介绍了如何隐藏密码字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的程序,在其中使用 if else 条件表达式添加了用户名和密码条目(无 GUI).
当我在程序中输入用户名时,它显示为简单的文本,没关系.
但是当我在密码字段中输入时,它也显示为简单的文本.
我希望密码像所有登录提示一样显示 *.

I created a simple program in which I added username and password entry (no GUI) by using an if else conditional expression.
When I type the username in program, it appears as simple text, and that's ok.
But when I type in the password field, it also appears as simple text.
I want the password instead to display * like all login prompts.

如何更改密码字段以显示 =>*****?

How do I change the password field to show => *****?

usr = (str(input('USERNAME : ')))
if usr == 'python':
  password = (str(input('PASSWORD : ')))
  if password == 'root':
    print ('login succesfull')
  else:
    print ('wrong password')
else:
  print ('wrong username')

推荐答案

getpass(),一个隐藏用户输入的函数:

 import getpass

 password = getpass.getpass()
 print(password)

 mypass = getpass.getpass("PASSWORD : ")

这篇关于如何隐藏密码字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆