PYTHON3 登录接口-用户名密码本地存储(更改版)

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Virgin Forest

###程序初始化-开始###
#加载SYS模块和GETPASS模块
import sys,getpass

#定义初始变量
user_pass = []
lock_user = []
user_list = []
pass_list = []
user_input = 0
pass_input = 0

#读取用户列表
user_file = open('access login user list.txt','r')
user_line = user_file.readlines()
user_file.close()
for i in user_line:
    user_pass_temporary = "".join(i.strip('\n').split())
    user_pass.append(user_pass_temporary)

for i in user_pass:
    long = user_pass.index(i)
    if long%2 == 0:
        user_list_temporary = "".join(i)
        user_list.append(user_list_temporary)
    if long%2 != 0:
        pass_list_temporary = "".join(i)
        pass_list.append(pass_list_temporary)


#读取锁定用户列表
user_lock = open('lockdown user list.txt','r')
lock_line = user_lock.readlines()
user_lock.close()
for i in lock_line:
    lock_user_temporary = "".join(i.strip('\n').split())
    lock_user.append(lock_user_temporary)
###程序初始化-结束###

###主程序###

while user_input < 3:
    input_user = input("username:")
    user_input += 1
    if input_user in lock_user:
        print("Sorry,You's account has been lockdown\nIf you want to unlock,Please contact administrator")
        sys.exit()
    else:
        if input_user in user_list:
            user_input=3
            long = user_list.index(input_user)
            while pass_input < 3:
                input_pass = getpass.getpass("password:")
                pass_input += 1
                if input_pass == pass_list[long]:
                    print("Welcome,%s"%(input_user))
                    pass_input = 3
                else:
                    if pass_input == 1:
                        print("Invalid password,Please try again!\nIf you enter the error password three times\nYour's account will be locked")
                    if pass_input == 2:
                        print("Invalid passowrd,Please try again!\nThis is your's last chance\nPlease confirm and type in")
                    if pass_input == 3:
                        print("Sorry,You have entered the wrong password more than three times\nYour's account will be locked")
                        file = open("lockdown user list.txt", "a")
                        li = ['\n%s' % input_user]
                        file.writelines(li)
                        file.close()
        else:
            if user_input < 3:
                print("Invalid username,Please try again!")
            else:
                print("Sorry,You have entered the wrong account more than three times\nPlease make sure the account is correct")
###主程序###

 

posted @ 2017-08-31 20:49  virgin-forest  阅读(609)  评论(0)    收藏  举报