# -*- coding: utf-8 -*-
__author__ = 'hujianli'
import json,os,sys
super_admin = "该程序为了防止用户记不住密码,初始了一个超管用户,超管用户admin,密码联系管理员询问:"
name = "请您输入注册后登录网页程序的用户名:"
passwd = "输入登录用户名所对应的密码: "
""" =====================普通用户登录板块======================== """
wellcome_jm = """\t恭喜您登录到本系统,用户名:{},密码{}.登录成功.请您牢记用户名密码, \n
送您一个链接地址: 网盘更新下载地址: http://pan.baidu.com/s/1sjsFrmX
github更新下载地址: https://github.com/liquanzhou/ops_doc """
""" ===============超管用户和白名单用户的创建=========="""
admin_file = "admin.json"
bmd_file = "baimingdan.json"
Hmd_file = "heimingdan.txt"
user_admin = {"admin": "123.com"} # 创建超管用户名称和密码
baimingdan = {"hujianli": "admin#123",
"huxiaojian": "admin#123",
"xiaofei": "admin#123"} # 普通登录用户 默认3位
if not os.path.isfile(admin_file):
with open(admin_file, "wt") as f:
json.dump(user_admin, f)
if not os.path.isfile(bmd_file):
with open(bmd_file, "wt") as f:
json.dump(baimingdan, f)
if not os.path.isfile(Hmd_file):
with open(Hmd_file, "wt") as f:
f.write("")
# 存储超管用户的用户和密码
with open("admin.json", "r") as f:
date = json.load(f)
date_keys = "".join(date.keys())
date_values = "".join(date.values())
# 存储白名单的用户和密码
userlist =[]
passwdlist = []
with open("baimingdan.json", "r") as f:
date_bmd = json.load(f)
#存储黑名单用户名和密码
with open("heimingdan.txt", "r") as f:
heimingdan = f.read().strip("\n")
""" ======================admin板块======================="""
def admin_mb():
# cazuolist = []
quanxian = """
(1)>>> 查看黑名单用户\t input:1
(2)>>>使用admin注册新的用户\t input:2
(3)>>>解除黑名单的指定用户\t input:3\n"""
admin_jm = """ 欢迎来到超级管理人登录界面,登录名admin,密码[],您可以有如下权限: \n%s\n""" % (quanxian)
print(admin_jm)
caozuo = int(input("请选择您的操作:"))
if caozuo == 1:
print(heimingdan)
elif caozuo == 2:
add_user = input(name)
add_passwd = input(passwd)
with open(bmd_file,"r") as f:
add_info = json.load(f)
if add_info[add_user] not in add_info.keys():
add_info[add_user] = add_passwd
with open(bmd_file,"a") as f:
json.dump(add_info,f)
else:
print("此用户已经存在,请勿重复创建%s!!!"% add_user)
elif caozuo == 3:
print("解除黑名单的指定用户,这个还没时间写,写法通过删掉黑名单的key和vlan实现")
sys.exit("退出```````")
else:
"error======"
pass
count = 0
while count <3:
count +=1
username = input(name)
with open(Hmd_file) as f:
heimingdan = f.readlines()
for lock_name in heimingdan:
lock_name = lock_name.strip("\n")
if username == lock_name:
sys.exit('=======WARNING:该账号 %s 已经被冻结========' % username)
if len(username) == 0 :
print("\033[1;31m用户名不能为空,错误操作\033[0m")
continue
#处理admin用户
if username == date_keys:
i = 0
while i <3:
i +=1
passwd_of_user = input(passwd)
if passwd_of_user == date_values:
admin_mb()
else:
if i !=3:
print('密码 %s 错误,请好好想想密码,生日或者身份证号码,还有 %d 次机会' % (passwd_of_user,3 -i))
else:
sys.exit("Sorry,健力提醒:由于您密码输入错误太多,只能退出程序..!!")
# 处理白名单用户
for key, value in date_bmd.items():
if username == key:
i = 0
while i <3:
i +=1
passwd_of_bmd_user = input(passwd)
if passwd_of_bmd_user == value:
print("===============================================================================================")
print("========================================普通用户使用平台========================================")
print("===============================================================================================")
print(wellcome_jm.format(username, passwd_of_bmd_user))
break
else:
if i !=3:
print('密码 %s 错误,请好好想想密码,生日或者身份证号码,还有 %d 次机会' % (username,3 -i))
else:
sys.exit("Sorry,健力提醒:由于您密码输入错误太多,只能退出程序..!!")
else:
count !=3
print("用户输入错误,还有 %d 次机会"%(3-count))
else:
with open(Hmd_file,"a+") as f:
f.write(username + "\n")
sys.exit("用户%s 达到最大登录次数,请联系超级管理员admin!!' " % username)
# dict_heimingdan = {}
# for i in range(1):
# name = input(BMD_user)
# password = input(BMD_passwd)
# if name not in dict_heimingdan.keys():
# dict_heimingdan[name] = password
#
# with open("heimingdan.json", "wt") as f:
# json.dump(dict_heimingdan, f)