Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 745 Bytes

1797.-design-authentication-manager.md

File metadata and controls

27 lines (19 loc) · 745 Bytes

1797. Design Authentication Manager

class AuthenticationManager:

    def __init__(self, timeToLive: int):
        self.t2l = timeToLive
        self.his = collections.defaultdict(int)
        

    def generate(self, tokenId: str, currentTime: int) -> None:
        self.his[tokenId] = currentTime + self.t2l

    def renew(self, tokenId: str, currentTime: int) -> None:
        if tokenId in self.his and self.his[tokenId] > currentTime :
            self.his[tokenId] = currentTime + self.t2l

    def countUnexpiredTokens(self, currentTime: int) -> int:
        cnt = 0
        # print(self.his,currentTime)
        for k, v in self.his.items():
            if v > currentTime:
                cnt += 1
        return cnt