用戶登陸,用已知的user和passwd登陸,先判斷用戶是否合法,然後輸入密碼,判斷密碼是否正確,如果輸入三次錯誤密碼,則自動跳出。否則輸出用戶error
#!/usr/bin/python
import getpass
#coding=utf-8
user = "root"
passwd = "westos"
username = raw_input("please input the username:")
if username == user:
password = getpass.getpass("please input the password:")
if password == passwd:
print "login success"
else:
password = getpass.getpass("please input the password again:")
if password == passwd:
print "login success"
else:
password = getpass.getpass("please input the password third:")
if password == passwd:
print "login success"
else:
print "you have no chance"
else:
print "username error"