forked from irving-rs/password_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
96 lines (79 loc) · 2.98 KB
/
password_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#password_generator.py
#Date: 27/September/2020
#by irving-rs
#Description:
#Password Generator: A simple, yet useful, aleatory password generator.
#Details:
#This password generator includes the following elements:
#Capital letters.
#Small letters.
#Numbers.
#Basic signs and symbols.
#Modules:
from random import randrange
#Functions:
def password(): #Generates password. Returns a string with the password.
list_1 = []
list_2 = []
paswd = ""
#Capital letters:
for i in range(upl):
x = randrange(len(uppercase)) #Aleatory generation.
list_1.append(uppercase[x]) #Capital letter storage.
#Small letters:
for i in range(lwl):
x = randrange(len(lowercase)) #Aleatory generation.
list_1.append(lowercase[x]) #Small letter storage.
#Numbers:
for i in range(num):
x = randrange(10) #Aleatory generation.
list_1.append(str(x)) #Number storage.
#Symbols and signs:
for i in range(sym):
x = randrange(len(symbols)) #Aleatory generation.
list_1.append(symbols[x]) #Number storage.
#Mixing the position of aleatory generated numbers:
for i in range(len(list_1)):
x = randrange(len(list_1)) #Mixing.
list_2.append(list_1[x]) #Rearranging.
del list_1[x]
paswd = paswd.join(list_2) #Convertion from list to string.
return paswd
def verify_input(): #Verifies the input. Returns True if correct, and False if wrong.
suma = upl + lwl + num + sym #Counts the number of digits.
if suma < 8: #If the number of digits do not reach 8.
print("\nPassword must contain at least 8 digits. Try again...\n")
return False
elif upl<1 or lwl<1 or num<1 or sym<1: #If does not contain a digit of a certain element.
print("\nPassword must contain at least 1 digit of each element. Try again...\n")
return False
else: #If the input is correct.
return True
#Variables:
escape = False
#Construction of variables (using ASCII table):
uppercase = [chr(i) for i in range(65,91)]
lowercase = [chr(i) for i in range(97,123)]
symbols = [chr(i) for i in range (33,48)]
for i in range(58,65):
symbols.append(chr(i))
for i in range(91,97):
symbols.append(chr(i))
for i in range(123,127):
symbols.append(chr(i))
#Presentation:
print("\nPassword Generator:\n")
#Instructions:
print("Instructions:")
print("1. Password must contain at least 8 digits.")
print("2. Password must contain at least 1 digit of the following elements:")
print(" a) Capital letters b) Small letters c) Numbers d)Basic signs and symbols\n")
#Main body:
while escape == False:
upl = int(input("a) Capital letters: "))
lwl = int(input("b) Small letters: "))
num = int(input("c) Numbers: "))
sym = int(input("d) Basic signs and symbols: "))
escape = verify_input()
paswd = password() #Generates the password.
print("\nThe resulting password is:", paswd, "\n")