python getpass模块:隐藏不显示输入的密码

案例:

1
2
3
4
5
6
7
8
9
10
11
12
13
import  getpass                                   #用于隐藏用户输入的字符串,常用来接收密码
def  checkuser(user,passwd):
     if  user  = =  'chenhang'  and  passwd  = =  '123456' :
         return  True
     else :
         return  False
if  __name__  = =  "__main__" :
     userr  =  input ( 'Input the user:' )
     passwdd  =  getpass.getpass( 'Input the passwd:' )
     if  checkuser(userr,passwdd):
         print ( 'OK!' )
     else :
         print ( 'ERROR!' )




本文转自 奚落123 51CTO博客,原文链接:http://blog.51cto.com/guyuyuan/1933271,如需转载请自行联系原作者