Create a small cross-platform CLI utility in Python that can generate or validate a token of the form: an 8-digit date in YYYYMMDD followed by exactly 32 alphanumeric characters. The suffix must use only [A-Za-z0-9]. The date portion must be a valid calendar date.
Deliverables
A single Python script saved to /app/token.py
The script should be executable with Python 3+ and rely only on the standard library.
Interface
Command: python3 /app/token.py generate
Output: a single line containing the token, e.g. 20231108Ab1Cd2Ef3Gh4Ij5Kl6Mn7Op8Qr9St0
Command: python3 /app/token.py validate
Output: VALID if the token matches the format and the date is valid, otherwise a descriptive INVALID message.
Requirements
The token format must be:
8 digits for the date: YYYYMMDD
Followed by exactly 32 characters, each from [A-Za-z0-9]
Total length: 40 characters
The date YYYYMMDD must be a real calendar date (e.g., 20210229 is invalid, 2020-02-29 is valid).
The suffix must be strictly alphanumeric; no punctuation allowed.
Example
Validation of a valid token: python3 /app/token.py validate 20231108Ab1Cd2Ef3Gh4Ij5Kl6Mn7Op8Qr9St0
Validation of an invalid token (bad length): python3 /app/token.py validate 20231108Ab1Cd2Ef3Gh4Ij5Kl6Mn7Op8Qr9St
Testing tips
Use Python's built-in datetime module for date validation.
Use random or secrets modules to generate a secure 32-character suffix.
Notes
The sample date shown in the examples is illustrative; implement full validation for real dates.