# author: Roberto Gradini
# mail: gradini.roberto@gmail.com
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
from random import *
import string
chars = string.ascii_letters + string.digits
def get_username(prompt="Enter your username: "):
print "Set your username (e.g. user@hostname.com)"
username = raw_input(prompt)
return username
def get_password_length(prompt="Enter the number of characters in your password between [8-32]: "):
password_length = raw_input(prompt)
if password_length == '':
print "Default value: 8"
password_length = 8
return password_length
def random_password(length):
return ''.join([choice(chars) for i in range(length)])
if __name__ == "__main__":
i = get_username()
n = int(get_password_length())
while n not in range(8,33):
n = int(get_password_length())
password = random_password(n)
# Save Login Information
login_information = ("\nLogin information: \n" + "username: " + i + "\n" + "password: " + password + "\n")
out_file = open("login_information.log", "a")
out_file.write(login_information)
out_file.close()
print "Done! Your login information was stored in login_information.log"
Usage: python script_name.py
roberto@curtis:~$ python password_generator.py
Set your username (e.g. user@hostname.com)
Enter your username: test@localhost.com
Enter the number of characters in your password between [8-32]: 15
Done! Your login information was stored in login_information.log
roberto@curtis:~$ cat login_information.log
Login information:
username: test@localhost.com
password: lm7argXv5RM9ihE

0 commenti:
Post a Comment