2019-07-07 15:17:38 +00:00
|
|
|
"""Password generator allows you to generate a random password of length N."""
|
2017-11-25 09:23:50 +00:00
|
|
|
from __future__ import print_function
|
2019-07-07 15:17:38 +00:00
|
|
|
from random import choice
|
|
|
|
from string import ascii_letters, digits, punctuation
|
|
|
|
|
|
|
|
|
|
|
|
def password_generator(length=8):
|
|
|
|
"""
|
|
|
|
>>> len(password_generator())
|
|
|
|
8
|
|
|
|
>>> 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
|
2017-09-28 21:35:52 +00:00
|
|
|
# ctbi= characters that must be in password
|
2019-07-07 15:17:38 +00:00
|
|
|
# i= how many letters or characters the password length will be
|
|
|
|
def alternative_password_generator(ctbi, i):
|
|
|
|
# Password generator = full boot with random_number, random_letters, and
|
|
|
|
# random_character FUNCTIONS
|
|
|
|
pass # Put your code here...
|
2018-01-06 06:54:10 +00:00
|
|
|
|
|
|
|
|
2017-09-28 21:35:52 +00:00
|
|
|
def random_number(ctbi, i):
|
2019-07-07 15:17:38 +00:00
|
|
|
pass # Put your code here...
|
2018-01-06 06:54:10 +00:00
|
|
|
|
|
|
|
|
2017-09-28 21:35:52 +00:00
|
|
|
def random_letters(ctbi, i):
|
2019-07-07 15:17:38 +00:00
|
|
|
pass # Put your code here...
|
2018-01-06 06:54:10 +00:00
|
|
|
|
|
|
|
|
2017-09-28 21:35:52 +00:00
|
|
|
def random_characters(ctbi, i):
|
2019-07-07 15:17:38 +00:00
|
|
|
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()
|