mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Use cryptographically secure random number for sms codes
Also, increase token length to 6 digits
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from random import SystemRandom
|
||||
from secrets import randbelow
|
||||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import joinedload
|
||||
@@ -19,16 +19,9 @@ def _remove_values_for_keys_if_present(dict, keys):
|
||||
dict.pop(key, None)
|
||||
|
||||
|
||||
def create_secret_code():
|
||||
return ''.join(get_non_repeating_random_digits(5))
|
||||
|
||||
|
||||
def get_non_repeating_random_digits(length):
|
||||
output = [None] * length
|
||||
for index in range(length):
|
||||
while output[index] in {None, output[index - 1]}:
|
||||
output[index] = str(SystemRandom().randrange(10))
|
||||
return output
|
||||
def create_secret_code(length=6):
|
||||
random_number = randbelow(10 ** length)
|
||||
return f"{random_number:06d}"
|
||||
|
||||
|
||||
def save_user_attribute(usr, update_dict=None):
|
||||
|
||||
Reference in New Issue
Block a user