Skip to content

Commit c55970d

Browse files
qckzrstokhos
authored andcommitted
Simplied password_generator.py (TheAlgorithms#968)
* Added print function into matrix_multiplication_addition.py and removed blank space in data_structures/binary tree directory * Removed .vs/ folder per TheAlgorithms#893 * Rename matrix_multiplication_addition.py to matrix_operation.py * Added main() function and simplified password generation. * Modified password_generator.py file according to suggestions in TheAlgorithms#968
1 parent 9128868 commit c55970d

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

Diff for: other/password_generator.py

+42-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
1+
"""Password generator allows you to generate a random password of length N."""
12
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
1925
# 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...
2431

2532

2633
def random_number(ctbi, i):
27-
pass # Put your code here...
34+
pass # Put your code here...
2835

2936

3037
def random_letters(ctbi, i):
31-
pass # Put your code here...
38+
pass # Put your code here...
3239

3340

3441
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

Comments
 (0)