|
| 1 | +"""Password generator allows you to generate a random password of length N.""" |
1 | 2 | from __future__ import print_function
|
2 |
| -import string |
3 |
| -import random |
4 |
| - |
5 |
| -letters = [letter for letter in string.ascii_letters] |
6 |
| -digits = [digit for digit in string.digits] |
7 |
| -symbols = [symbol for symbol in string.punctuation] |
8 |
| -chars = letters + digits + symbols |
9 |
| -random.shuffle(chars) |
10 |
| - |
11 |
| -min_length = 8 |
12 |
| -max_length = 16 |
13 |
| -password = ''.join(random.choice(chars) for x in range(random.randint(min_length, max_length))) |
14 |
| -print('Password: ' + password) |
15 |
| -print('[ If you are thinking of using this passsword, You better save it. ]') |
16 |
| - |
17 |
| - |
18 |
| -# ALTERNATIVE METHODS |
| 3 | +from random import choice |
| 4 | +from string import ascii_letters, digits, punctuation |
| 5 | + |
| 6 | + |
| 7 | +def password_generator(length=8): |
| 8 | + """ |
| 9 | + >>> len(password_generator()) |
| 10 | + 8 |
| 11 | + >>> len(password_generator(length=16)) |
| 12 | + 16 |
| 13 | + >>> len(password_generator(257)) |
| 14 | + 257 |
| 15 | + >>> len(password_generator(length=0)) |
| 16 | + 0 |
| 17 | + >>> len(password_generator(-1)) |
| 18 | + 0 |
| 19 | + """ |
| 20 | + chars = tuple(ascii_letters) + tuple(digits) + tuple(punctuation) |
| 21 | + return ''.join(choice(chars) for x in range(length)) |
| 22 | + |
| 23 | + |
| 24 | +# ALTERNATIVE METHODS |
19 | 25 | # ctbi= characters that must be in password
|
20 |
| -# i= how many letters or characters the password length will be |
21 |
| -def password_generator(ctbi, i): |
22 |
| - # Password generator = full boot with random_number, random_letters, and random_character FUNCTIONS |
23 |
| - pass # Put your code here... |
| 26 | +# i= how many letters or characters the password length will be |
| 27 | +def alternative_password_generator(ctbi, i): |
| 28 | + # Password generator = full boot with random_number, random_letters, and |
| 29 | + # random_character FUNCTIONS |
| 30 | + pass # Put your code here... |
24 | 31 |
|
25 | 32 |
|
26 | 33 | def random_number(ctbi, i):
|
27 |
| - pass # Put your code here... |
| 34 | + pass # Put your code here... |
28 | 35 |
|
29 | 36 |
|
30 | 37 | def random_letters(ctbi, i):
|
31 |
| - pass # Put your code here... |
| 38 | + pass # Put your code here... |
32 | 39 |
|
33 | 40 |
|
34 | 41 | def random_characters(ctbi, i):
|
35 |
| - pass # Put your code here... |
| 42 | + pass # Put your code here... |
| 43 | + |
| 44 | + |
| 45 | +def main(): |
| 46 | + length = int( |
| 47 | + input('Please indicate the max length of your password: ').strip()) |
| 48 | + print('Password generated:', password_generator(length)) |
| 49 | + print('[If you are thinking of using this passsword, You better save it.]') |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + main() |
0 commit comments