mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
Simplied password_generator.py (#968)
* Added print function into matrix_multiplication_addition.py and removed blank space in data_structures/binary tree directory * Removed .vs/ folder per #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 #968
This commit is contained in:
parent
9532492728
commit
234b0a77c4
@ -1,35 +1,53 @@
|
|||||||
|
"""Password generator allows you to generate a random password of length N."""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import string
|
from random import choice
|
||||||
import random
|
from string import ascii_letters, digits, punctuation
|
||||||
|
|
||||||
letters = [letter for letter in string.ascii_letters]
|
|
||||||
digits = [digit for digit in string.digits]
|
|
||||||
symbols = [symbol for symbol in string.punctuation]
|
|
||||||
chars = letters + digits + symbols
|
|
||||||
random.shuffle(chars)
|
|
||||||
|
|
||||||
min_length = 8
|
def password_generator(length=8):
|
||||||
max_length = 16
|
"""
|
||||||
password = ''.join(random.choice(chars) for x in range(random.randint(min_length, max_length)))
|
>>> len(password_generator())
|
||||||
print('Password: ' + password)
|
8
|
||||||
print('[ If you are thinking of using this passsword, You better save it. ]')
|
>>> len(password_generator(length=16))
|
||||||
|
16
|
||||||
|
>>> len(password_generator(257))
|
||||||
|
257
|
||||||
|
>>> len(password_generator(length=0))
|
||||||
|
0
|
||||||
|
>>> len(password_generator(-1))
|
||||||
|
0
|
||||||
|
"""
|
||||||
|
chars = tuple(ascii_letters) + tuple(digits) + tuple(punctuation)
|
||||||
|
return ''.join(choice(chars) for x in range(length))
|
||||||
|
|
||||||
|
|
||||||
# ALTERNATIVE METHODS
|
# ALTERNATIVE METHODS
|
||||||
# ctbi= characters that must be in password
|
# ctbi= characters that must be in password
|
||||||
# i= how many letters or characters the password length will be
|
# i= how many letters or characters the password length will be
|
||||||
def password_generator(ctbi, i):
|
def alternative_password_generator(ctbi, i):
|
||||||
# Password generator = full boot with random_number, random_letters, and random_character FUNCTIONS
|
# Password generator = full boot with random_number, random_letters, and
|
||||||
pass # Put your code here...
|
# random_character FUNCTIONS
|
||||||
|
pass # Put your code here...
|
||||||
|
|
||||||
|
|
||||||
def random_number(ctbi, i):
|
def random_number(ctbi, i):
|
||||||
pass # Put your code here...
|
pass # Put your code here...
|
||||||
|
|
||||||
|
|
||||||
def random_letters(ctbi, i):
|
def random_letters(ctbi, i):
|
||||||
pass # Put your code here...
|
pass # Put your code here...
|
||||||
|
|
||||||
|
|
||||||
def random_characters(ctbi, i):
|
def random_characters(ctbi, i):
|
||||||
pass # Put your code here...
|
pass # Put your code here...
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
length = int(
|
||||||
|
input('Please indicate the max length of your password: ').strip())
|
||||||
|
print('Password generated:', password_generator(length))
|
||||||
|
print('[If you are thinking of using this passsword, You better save it.]')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user