1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| #!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import json
import random
###取得绝对路径下的账号密码文件
BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
filepath= "%s\\username_passwd" % BASE_DIR
print("进入用户登录页面")
###外套的校验码程序
def deco(func):
def _deco():
randomnum = str(random.randrange(1000, 10000))
print("验证码:",randomnum)
inputrandomnum=input("请输入验证码:")
if inputrandomnum == randomnum:
func()
return func
else:
print("验证码输入错误")
exit()
return _deco
###
#@deco
def authentication():
username = input("请输入用户名:")
passwd = input("请输入密码:")
f=open(filepath,'r',encoding='utf-8')
date = json.loads(f.read())
try:
if date[username] == passwd:
print("用户名密码认证通过")
return True
else:
print("密码错误,请重新输入")
except KeyError:
print("不存在的用户")
_authentication=deco(authentication) ###这里指向deco(func)内存中的地址
pass_tag = _authentication() ###这里等于deco(func)(),或者deco._deco()
|