mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 08:58:30 +01:00
Replace random with secrets
This commit is contained in:
parent
b516b8343b
commit
0d7c946ba8
2 changed files with 4 additions and 5 deletions
|
@ -1,6 +1,5 @@
|
|||
import dataclasses
|
||||
import secrets
|
||||
import random
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
import arrow
|
||||
|
@ -233,7 +232,7 @@ def generate_activation_code(
|
|||
if config.MAILBOX_VERIFICATION_OVERRIDE_CODE:
|
||||
code = config.MAILBOX_VERIFICATION_OVERRIDE_CODE
|
||||
else:
|
||||
code = "{:06d}".format(random.randint(1, 999999))
|
||||
code = "{:06d}".format(secrets.randbelow(1000000))[:6]
|
||||
else:
|
||||
code = secrets.token_urlsafe(16)
|
||||
return MailboxActivation.create(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import random
|
||||
import re
|
||||
import secrets
|
||||
import string
|
||||
|
@ -32,8 +31,9 @@ def random_words(words: int = 2, numbers: int = 0):
|
|||
fields = [secrets.choice(_words) for i in range(words)]
|
||||
|
||||
if numbers > 0:
|
||||
digits = "".join([str(random.randint(0, 9)) for i in range(numbers)])
|
||||
return "_".join(fields) + digits
|
||||
digits = [n for n in range(10)]
|
||||
suffix = "".join([str(secrets.choice(digits)) for i in range(numbers)])
|
||||
return "_".join(fields) + suffix
|
||||
else:
|
||||
return "_".join(fields)
|
||||
|
||||
|
|
Loading…
Reference in a new issue