Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- LOWERCASE_CHARS = tuple(map(chr, range(ord('a'), ord('z')+1)))
- UPPERCASE_CHARS = tuple(map(chr, range(ord('A'), ord('Z')+1)))
- DIGITS = tuple(map(str, range(0, 10)))
- SPECIALS = ('!', '@', '#', '$', '%', '^', '&', '*')
- SEQUENCE = (LOWERCASE_CHARS,
- UPPERCASE_CHARS,
- DIGITS,
- SPECIALS,
- )
- def generate_random_password(total, sequences):
- r = _generate_random_number_for_each_sequence(total, len(sequences))
- password = []
- for (population, k) in zip(sequences, r):
- n = 0
- while n < k:
- position = random.randint(0, len(population)-1)
- password += population[position]
- n += 1
- random.shuffle(password)
- while _is_repeating(password):
- random.shuffle(password)
- return ''.join(password)
- def _generate_random_number_for_each_sequence(total, sequence_number):
- current_total = 0
- r = []
- for n in range(sequence_number-1, 0, -1):
- current = random.randint(1, total - current_total - n)
- current_total += current
- r.append(current)
- r.append(total - sum(r))
- random.shuffle(r)
- return r
- def _is_repeating(password):
- n = 1
- while n < len(password):
- if password[n] == password[n-1]:
- return True
- n += 1
- return False
- intnum = tuple(map(str, range(1, 1001)))
- passamount = str(intnum[-1])
- passwordgenerator = generate_random_password(random.randint(6, 30), SEQUENCE)
- charcount = len(passwordgenerator)
- if __name__ == '__main__':
- f = open("generated_passwords.txt", "w")
- f.write("" + passamount + " strong password(s) were generated.\n\n")
- for num in intnum:
- f.write("[" + str(charcount) + " | RANDOM." + num + "]: " + passwordgenerator + "\n")
- f.write("\nSave the password you want!")
- print("Generated " + passamount + " random passwords in \'generated_passwords.txt\'.")
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement