From 364e07daa11c77a0dccb96d9fda7faecf90ce147 Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 25 Nov 2024 13:14:07 +0100 Subject: [PATCH] fix: fixed random issue (codacy) --- creyPY/helpers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/creyPY/helpers.py b/creyPY/helpers.py index bfb334b..7773e98 100644 --- a/creyPY/helpers.py +++ b/creyPY/helpers.py @@ -1,4 +1,4 @@ -import random +import secrets import string @@ -6,11 +6,11 @@ def create_random_password(length: int = 12) -> str: all_characters = string.ascii_letters + string.digits + string.punctuation password = [ - random.choice(string.ascii_lowercase), - random.choice(string.ascii_uppercase), - random.choice(string.digits), - random.choice(string.punctuation), + secrets.choice(string.ascii_lowercase), + secrets.choice(string.ascii_uppercase), + secrets.choice(string.digits), + secrets.choice(string.punctuation), ] - password += random.choices(all_characters, k=length - 4) - random.shuffle(password) + password += [secrets.choice(all_characters) for _ in range(length - 4)] + secrets.SystemRandom().shuffle(password) return "".join(password)