diff --git a/src/main.py b/src/main.py index fc9a525..fc7b87d 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,43 @@ # Resolve the problem!! import string +import random SYMBOLS = list('!"#$%&\'()*+,-./:;?@[]^_`{|}~') - +UPPERCASES = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') +LOWERCASES = list('abcdefghijklmnopqrstuvwxyz') +DIGITS = list('0123456789') def generate_password(): - # Start coding here + """ + 1. Create a list with a random lenght between 8 and 16, filled with x + 2. Fill the list with every type of characters radomly, diff. even and odd + 3. Because the list was filled with an even-odd index order, it must be shuffle randomly + """ + + length = random.randint(8, 16) + password = list('x' * length) + + i = 0 + while i < length/2: + if i%2 == 0: + password[i] = SYMBOLS[random.randint(0, len(SYMBOLS)-1)] + i += 1 + else: + password[i] = DIGITS[random.randint(0, len(DIGITS)-1)] + i += 1 + + while i < length: + if i%2 == 0: + password[i] = UPPERCASES[random.randint(0, len(UPPERCASES)-1)] + i += 1 + else: + password[i] = LOWERCASES[random.randint(0, len(LOWERCASES)-1)] + i += 1 + + random.shuffle(password) + str_pass = '' + + return str_pass.join(password) def validate(password):