Gitlab Community Edition Instance

Skip to content
Snippets Groups Projects

Replacing word based passwords with totally random passwords

Closed Jan Maximilian Michal requested to merge remove-dict-words-file into master
2 files
+ 7
11
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 7
8
import configparser
import secrets
import string
from core.models import UserAccount as User
from core.models import Reviewer, Student, Tutor
@@ -11,12 +12,10 @@ REVIEWERS = 'reviewers'
PASSWORDS = '.importer_passwords'
def get_xkcd_password(k=2):
with open('/usr/share/dict/words') as words:
choose_from = list({word.strip().lower()
for word in words if 5 < len(word) < 8})
return ''.join(secrets.choice(choose_from) for _ in range(k))
def get_random_password(length=32):
""" Returns a cryptographically random string of specified length """
return ''.join(secrets.choice(string.ascii_lowercase)
for _ in range(length))
def store_password(username, groupname, password):
@@ -35,7 +34,7 @@ def store_password(username, groupname, password):
class GradyUserFactory:
def __init__(self,
password_generator_func=get_xkcd_password,
password_generator_func=get_random_password,
password_storge=store_password,
*args, **kwargs):
self.password_generator_func = password_generator_func
@@ -43,7 +42,7 @@ class GradyUserFactory:
@staticmethod
def _get_random_name(prefix='', suffix='', k=1):
return ''.join((prefix, get_xkcd_password(k), suffix))
return ''.join((prefix, get_random_password(k), suffix))
def _make_base_user(self, username, groupname, store_pw=False, **kwargs):
""" This is a specific wrapper for the django update_or_create method of
Loading