一、六位验证码
6位随机验证码程序,要求验证码至少有一个数字、小写字母、大小字母
import random
import string
code = []
code.append(random.choice(string.ascii_uppercase))
code.append(random.choice(string.ascii_lowercase))
code.append(random.choice(string.digits))
while len(code)<6:
code.append(random.choice(string.ascii_lowercase+string.ascii_uppercase+string.digits))
code = ''.join(code)
二、登录小程序
用户名为JSON的文件名 判断是否过期 登录成功后应答登录成功,三次登录失败,status值修改为1,并且锁定账号文件名格式:
{ "expire_date": "2021-01-01", "id": "1234", "status": 0, "pay_dat": 22, "password": "123abc" }
import json
import pathlib
import time
times = 0
flag = False
while times < 3:
username = input("请输入用户名").strip()
filename = username + '.json'
script_path = pathlib.PurePath(__file__).parent
userinfo_path = pathlib.Path(script_path).joinpath(filename)
if pathlib.Path(userinfo_path).is_file():
with open(userinfo_path, 'r', encoding='utf-8') as fs:
user = json.load(fs)
if user['status'] == 1:
print("用户已经被锁定")
break
else:
expire_date = user['exipre_date']
current_date = time.time() #当前时间戳
expire_mk = time.mktime(time.strptime(expire_date, '%Y-%m-%d'))
#比较时间
if current_date > expire_mk:
print("用户已经过期")
break
else:
while times < 3:
passwd = input("请输入用户密码: ").strip()
if passwd == user['password']:
print("登录成功")
expire_mk = True
else:
print("密码错误")
times += 1
continue
else:
print("输入用户名有误,文件不存在")