fix: 修复暴力校验验证码

pull/11699/head
ibuler 2023-09-25 21:49:47 +08:00 committed by Bryan
parent 96f69c821b
commit f65e2ac15f
1 changed files with 7 additions and 0 deletions

View File

@ -26,6 +26,7 @@ class SendAndVerifyCodeUtil(object):
self.target = target
self.backend = backend
self.key = key or self.KEY_TMPL.format(target)
self.verify_key = self.key + '_verify'
self.timeout = settings.VERIFY_CODE_TTL if timeout is None else timeout
self.other_args = kwargs
@ -47,6 +48,11 @@ class SendAndVerifyCodeUtil(object):
raise
def verify(self, code):
times = cache.get(self.verify_key, 0)
if times >= 3:
self.__clear()
raise CodeExpired
cache.set(self.verify_key, times + 1, timeout=self.timeout)
right = cache.get(self.key)
if not right:
raise CodeExpired
@ -59,6 +65,7 @@ class SendAndVerifyCodeUtil(object):
def __clear(self):
cache.delete(self.key)
cache.delete(self.verify_key)
def __ttl(self):
return cache.ttl(self.key)