app icon indicating copy to clipboard operation
app copied to clipboard

Refine activation code generation.

Open weakish opened this issue 3 years ago • 2 comments

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.

weakish avatar Aug 10 '22 13:08 weakish

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:

acasajus avatar Aug 10 '22 14:08 acasajus

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.)

weakish avatar Aug 10 '22 16:08 weakish