码迷,mamicode.com
首页 > 其他好文 > 详细

51_work--模拟登陆

时间:2017-07-04 11:06:08      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:pwd   lin   inpu   time   pass   exit   readlines   file   man   

import sys
count=0
while count<3:
    user = input("Please enter user name:")

    lock_file = open(‘D:\\lock.txt‘, ‘r+‘)
    lock_list = lock_file.readlines()
    for lock_line in lock_list:
        lock_line = lock_line.strip(‘\n‘)
        if user == lock_line:
            print(‘The user has been locked‘)
            sys.exit()

    user_file = open("D:\\username.txt", ‘r‘)
    user_list = user_file.readlines()
    for user_line in user_list:
        name, pwd = user_line.strip(‘\n‘).split()
        if user == name:
            count_1 = 0
            while count_1 < 3:
                password = input(‘Please enter user password:‘)
                if password == pwd:
                    print(‘%s welcome!‘ % user)
                    sys.exit()
                else:
                    print(‘Password error‘)
                    count_1 += 1
            if count_1 == 3:
                print(‘The password has been entered many times. The user has been locked‘)
                lock_file.write(user)
                sys.exit()
        else:
            pass
    else:
        if count != 2:
            print(‘The username does not exist‘)
    count += 1
else:
    print(‘The username has been entered many times‘)
    sys.exit()

 

51_work--模拟登陆

标签:pwd   lin   inpu   time   pass   exit   readlines   file   man   

原文地址:http://www.cnblogs.com/zy-study/p/7115229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!