# 制作一个简单的验证码,可以定时更新,保证数据安全性。
from threading import Timer
import random
class Code():
def __init__(self):
self.make_cache()
def make_cache(self,interval=10): # 缓存
self.cache = self.make_code()
print(self.cache)
self.t = Timer(interval,self.make_cache)
self.t.start()
def make_code(self):
res = ''
for i in range(4):
s1 = str(random.randint(0,9))
s2 = chr(random.randint(65,90)) #26个大小写字母
res += random.choice([s1,s2])
return res
def check(self):
while True:
code = input('请输入验证码>>:').strip()
if code.upper() ==self.cache:
print('验证码输入正确!!')
self.t.cancel()
break
obj = Code()
obj.check()
制作一个简单的验证码,可以定时更新验证码(使用线程的Timer方法)
最新推荐文章于 2022-05-04 22:16:33 发布
该博客介绍了制作简单验证码的方法,可通过线程的Timer方法实现验证码的定时更新,属于信息技术领域中验证码制作相关内容。
239

被折叠的 条评论
为什么被折叠?



