Name:  LoginAuth.py

Fuctions: 登录验证、隐藏输入密码、同一用户3次输入错误密码锁定该账户、如果用户名为yooma密码                  为yooma 则登录成功提示欢迎

code:

#!/usr/bin/env python3
#Auther:yooma 2016-08-15 15:00

import sys
import getpass


c = 1

uname = []

while 1:
    username = input("Input username:")
    password = getpass.getpass("Input password:")

    LockFile = open('lock.txt','r')
    try:
        if username == LockFile.read():
            print("%s user locked." % username)
            sys.exit(0)
    finally:
        LockFile.close()
    if username == 'yooma' and password == 'yooma':
        print("Welcome %s login success!" % username)
        break
    elif username != 'yooma' or password != 'yooma':
        print("Username or password failed,please input again:")
        uname.insert(c,username)
        s = set(uname)
        for i in s:
           if c < 4 and uname.count(i) == 3:
               LockFile = open('lock.txt','w')
               try:
                   LockFile.write(username)
               finally:
                   LockFile.close()
                   print("Your account is locked.")
                   sys.exit(0)
           elif c == 3:
               print("Input error 3 times,go out.")
               sys.exit(0)
        c+=1
        continue
    else:
        print("Input error.")
        break