← 返回 databricks 的题目列表Implement an Authentication Class
类型:online_judge
Write an authentication class with the following features:
User Registration: Accepts username and password, checks if the username already exists.
User Login: Accepts username and password, verify user identity.
Password Encryption: All stored passwords must be encrypted.
Token Generation: On successful login, generate a unique token, with this token required for future requests. Tokens should have an expiration period.
Input
Registration: method register(username: str, password: str)
Login: method login(username: str, password: str) -> str returns token
Authentication: method authenticate(token: str) -> bool
Output
Registration has no return.
Login returns token value on success.
Authentication returns true on success, else false.
Test Cases
# Test Case 1
auth = Authentication()
auth.register("user1", "password1") # Register user
assert auth.login("user1", "password1") # Login user
Data Scale
Username and password have a maximum length of 100 characters.
Maximum simultaneous logged-in users is 1000.
Example
Input
register user1 password1
login user1 password1
authorize token123456