1
1
"""Password generator allows you to generate a random password of length N."""
2
- from random import choice
2
+ from random import choice , shuffle
3
3
from string import ascii_letters , digits , punctuation
4
4
5
5
@@ -26,9 +26,22 @@ def password_generator(length=8):
26
26
def alternative_password_generator (ctbi , i ):
27
27
# Password generator = full boot with random_number, random_letters, and
28
28
# random_character FUNCTIONS
29
- pass # Put your code here...
30
-
29
+ # Put your code here...
30
+ i = i - len (ctbi )
31
+ quotient = int (i / 3 )
32
+ remainder = i % 3
33
+ #chars = ctbi + random_letters(ascii_letters, i / 3 + remainder) + random_number(digits, i / 3) + random_characters(punctuation, i / 3)
34
+ chars = ctbi + random (ascii_letters , quotient + remainder ) + random (digits , quotient ) + random (punctuation , quotient )
35
+ chars = list (chars )
36
+ shuffle (chars )
37
+ return "" .join (chars )
31
38
39
+
40
+ #random is a generalised function for letters, characters and numbers
41
+ def random (ctbi , i ):
42
+ return "" .join (choice (ctbi ) for x in range (i ))
43
+
44
+
32
45
def random_number (ctbi , i ):
33
46
pass # Put your code here...
34
47
@@ -43,7 +56,9 @@ def random_characters(ctbi, i):
43
56
44
57
def main ():
45
58
length = int (input ("Please indicate the max length of your password: " ).strip ())
59
+ ctbi = input ("Please indicate the characters that must be in your password: " ).strip ()
46
60
print ("Password generated:" , password_generator (length ))
61
+ print ("Alternative Password generated:" , alternative_password_generator (ctbi , length ))
47
62
print ("[If you are thinking of using this passsword, You better save it.]" )
48
63
49
64
0 commit comments