diff --git a/install/install.py b/install/install.py index 07051aad4..adac85595 100755 --- a/install/install.py +++ b/install/install.py @@ -23,34 +23,9 @@ char_set = {'small': 'abcdefghijklmnopqrstuvwxyz', def generate_pass(length=14): - """Function to generate a password""" - - password = [] - - while len(password) < length: - key = choice(char_set.keys()) - a_char = urandom(1) - if a_char in char_set[key]: - if check_prev_char(password, char_set[key]): - continue - else: - password.append(a_char) - return ''.join(password) - - -def check_prev_char(password, current_char_set): - """Function to ensure that there are no consecutive - UPPERCASE/lowercase/numbers/special-characters.""" - - index = len(password) - if index == 0: - return False - else: - prev_char = password[index - 1] - if prev_char in current_char_set: - return True - else: - return False + chars = string.ascii_uppercase + string.ascii_lowercase + string.digits + size = length + return ''.join(random.choice(chars) for x in range(size)) # There can not be peace without first a great suffering. diff --git a/install/randomPassword.py b/install/randomPassword.py index 2eb292e45..9cfe205f5 100755 --- a/install/randomPassword.py +++ b/install/randomPassword.py @@ -1,38 +1,7 @@ -from os import urandom -from random import choice - -char_set = {'small': 'abcdefghijklmnopqrstuvwxyz', - 'nums': '0123456789', - 'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', - } - +import string +import random def generate_pass(length=14): - """Function to generate a password""" - - password = [] - - while len(password) < length: - key = choice(char_set.keys()) - a_char = urandom(1) - if a_char in char_set[key]: - if check_prev_char(password, char_set[key]): - continue - else: - password.append(a_char) - return ''.join(password) - - -def check_prev_char(password, current_char_set): - """Function to ensure that there are no consecutive - UPPERCASE/lowercase/numbers/special-characters.""" - - index = len(password) - if index == 0: - return False - else: - prev_char = password[index - 1] - if prev_char in current_char_set: - return True - else: - return False \ No newline at end of file + chars = string.ascii_uppercase + string.ascii_lowercase + string.digits + size = length + return ''.join(random.choice(chars) for x in range(size)) \ No newline at end of file diff --git a/plogical/randomPassword.py b/plogical/randomPassword.py index 699ad3963..9cfe205f5 100755 --- a/plogical/randomPassword.py +++ b/plogical/randomPassword.py @@ -1,38 +1,7 @@ -from os import urandom -from random import choice - -char_set = {'small': 'abcdefghijklmnopqrstuvwxyz', - 'nums': '0123456789', - 'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', - } - +import string +import random def generate_pass(length=14): - """Function to generate a password""" - - password = [] - - while len(password) < length: - key = choice(list(char_set.keys())) - a_char = urandom(1) - if a_char in char_set[key]: - if check_prev_char(password, char_set[key]): - continue - else: - password.append(a_char) - return ''.join(password) - - -def check_prev_char(password, current_char_set): - """Function to ensure that there are no consecutive - UPPERCASE/lowercase/numbers/special-characters.""" - - index = len(password) - if index == 0: - return False - else: - prev_char = password[index - 1] - if prev_char in current_char_set: - return True - else: - return False \ No newline at end of file + chars = string.ascii_uppercase + string.ascii_lowercase + string.digits + size = length + return ''.join(random.choice(chars) for x in range(size)) \ No newline at end of file