# _*_ coding:cp936 _*_ //Support Chinese format import sys import getpass#admin configurationusername= ' Cheeron ' password= ' 1234 ' Counter = 0 #认证登录while True: If counter <3: name = raw_input (' Please input your name: '). Strip () If Len (nam e) = = 0: print ' empty name,try again! ' Continue #passwd = raw_input (' Please input your password: ') #使用密码隐藏, getpass function passwd = Getpass.getpass (' Please input your password ') if password = = passwd and Username = = Name: print ' Welcome to sign in!%s '% NAME
else: print ' name or password is not valid,please try Again! ' Counter+=1 Continue break else: print ' exceeded 3 times user login...exit the script ' Sys.exit ()
Result: [[email protected] lesson1]#./qr.py Please input your name:empty name,try again! Please input your name:cheeronplease input your passwordwelcome to sign in Cheeron ... [Email protected] lesson1]#./qr.py Please input your name:cheeronplease input your passwordname or password are not Vali D,please Try Again! Please input your name:cheeronplease input your passwordname or password are not valid,please try Again! Please input your name:cheeronplease input your passwordname or password are not valid,please try again!exceeded 3 times u Ser login...exit the script
python--User Authentication Login implementation