From 7bb5d6f313479dd6add4c6477d8a7e84f7c45836 Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 28 Jun 2022 11:13:23 +0300 Subject: [PATCH] update secret generator with new python secrets module - urlsafe --- conf/runit/secret_generator.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/conf/runit/secret_generator.py b/conf/runit/secret_generator.py index e22ca7b..70ee032 100644 --- a/conf/runit/secret_generator.py +++ b/conf/runit/secret_generator.py @@ -1,5 +1,13 @@ -import random -import string +import secrets -haystack = string.ascii_letters + string.digits + string.punctuation -print(''.join([random.SystemRandom().choice(haystack.replace('/', '').replace('\'', '').replace('\"', '')) for _ in range(50)])) +generated_key = secrets.token_urlsafe(50) + +print(''.join(generated_key)) + + +### Use for old python versions < 3.6 +##import random +##import string +# +##haystack = string.ascii_letters + string.digits + string.punctuation +##print(''.join([random.SystemRandom().choice(haystack.replace('/', '').replace('\'', '').replace('\"', '')) for _ in range(50)]))