1797. Design Authentication Manager
On This Page
class AuthenticationManager:
def __init__(self, timeToLive: int):
self.t = timeToLive
self.d = defaultdict(int)
def generate(self, tokenId: str, currentTime: int) -> None:
self.d[tokenId] = currentTime + self.t
def renew(self, tokenId: str, currentTime: int) -> None:
if self.d[tokenId] <= currentTime:
return
self.d[tokenId] = currentTime + self.t
def countUnexpiredTokens(self, currentTime: int) -> int:
return sum(exp > currentTime for exp in self.d.values())
# Your AuthenticationManager object will be instantiated and called as such:
# obj = AuthenticationManager(timeToLive)
# obj.generate(tokenId,currentTime)
# obj.renew(tokenId,currentTime)
# param_3 = obj.countUnexpiredTokens(currentTime)