Python 用户输入用户名,进行验证

Python 征程(用户输入名字进行密码验证)

#!/usr/bin/env python

account_file = file('account.txt')
user_list = account_file.readlines();


while True:
    lock_file = file('lock.txt')
    lock_list = []
    for line in lock_file.readlines():
        lock_list.append(line.strip('
'))

    username = raw_input('username:').strip()

    print lock_list

    if username in lock_list:
        print 'sorry %s are in black list!' % username
        exit(0)
    if len(username) == 0:
        print 'user can not empty'
    else:
        for line in user_list:
            if username == line.split()[0]:
                for i in range(3):
                    password = raw_input('password').strip()
                    for line in user_list:
                        if password == line.split()[1]:
                            print 'Welcome %s to my system !' % username
                            exit(0)

                print 'password has incorrent three times' 
                lock_file = file('lock.txt','a') 
                lock_file.write('
%s' % username)
                lock_file.close()
                break
        print '%s are not in system account' % username 

 文件account.txt(用户保存文件)

  luowen admin

  admin 123

文件 lock.txt(黑名单文件)

  

原文地址:https://www.cnblogs.com/luowen/p/python.html