mirror of https://github.com/jumpserver/jumpserver
fix: 修复暴力校验验证码
parent
96f69c821b
commit
f65e2ac15f
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue