app
app copied to clipboard
Refine activation code generation.
Previously, activation code genaration invoked a redudant str() conversion
(secrets.cohice(string.digits) already returns a string).
Also, secrets.choice was called six times, which is slower than just one call.
I hope this refinement make the code more readable and faster.
Hey, thanks for contributing! May I suggest a small improvement.
At the top define
ACTIVATION_CODE_NUM_DIGITS=6
and then we can do
str(secrets.randbelow(10**ACTIVATION_CODE_NUM_DIGITS)).zfill(ACTIVATION_CODE_NUM_DIGITS)
:+1:
I applied suggestion in e2b147f (I defined the const in config.py instead of the top of auth.py since it seems most constants are defined there.)