Created
December 23, 2019 17:25
-
-
Save glof2/5cefa9ad08eb2e869a32d885a65db045 to your computer and use it in GitHub Desktop.
Password Generator by MayooXD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple password generator by MayooXD | |
import random | |
import datetime | |
from colorama import Fore, init | |
from os import system, name | |
init() | |
# | |
def clear(): | |
# for windows | |
if name == 'nt': | |
_ = system('cls') | |
# for mac and linux(here, os.name is 'posix') | |
else: | |
_ = system('clear') | |
def fileSave(fileName, whatToDo, whatToSave, whatIsSaved): | |
time= str(datetime.datetime.now()) | |
save = open(fileName, whatToDo) | |
save.write(whatIsSaved + " saved at "+time+ "\n"+"---------------\n"+whatToSave+"\n"+"---------------\n") | |
save.close() | |
def numsInSeed(seed): | |
numberseed = "" | |
for a in seed: | |
if (a.isdigit()==True): | |
numberseed += a | |
else: | |
pass | |
return numberseed | |
def upperInSeed(seed): | |
numberseed = "" | |
for a in seed: | |
if (a.isupper()==True): | |
numberseed += a | |
else: | |
pass | |
return numberseed | |
def lowerInSeed(seed): | |
numberseed = "" | |
for a in seed: | |
if (a.islower()==True): | |
numberseed += a | |
else: | |
pass | |
return numberseed | |
#User settings | |
run = True | |
while (run == True): | |
clear() | |
print("Password lenght:") | |
try: | |
passwrdlenght = int(input()) | |
except: | |
print(Fore.RED + "Unexpected value. Setting password lenght to 12..." + Fore.WHITE) | |
passwrdlenght = 12 | |
print("Do you want to input your custom seed? (y/n)") | |
seed = input() | |
if (seed.lower() == "y"): | |
print("Seed (example: ABC512abc):") | |
seed=input() | |
else: | |
seed="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz111222333444555666777888999000..!!@@##$$^^&&**(())--__==++" | |
print("------------------------------------------------------------------") | |
print("Shuffling the seed...") | |
seed = ''.join(random.sample(seed,len(seed))) | |
print("Generating "+str(passwrdlenght)+" characters long password with the seed: " + seed) | |
#Password generation | |
passwrdlenghtgen = passwrdlenght | |
passwrd= "" | |
while (passwrdlenghtgen != 0): | |
i = random.choice(seed) | |
passwrd += i | |
passwrdlenghtgen -= 1 | |
passwrd = ''.join(random.sample(passwrd,passwrdlenght)) | |
#Password check | |
digits = capital = lowercase = 0 | |
#Content check | |
for a in passwrd: | |
if (a.isdigit()==True): | |
digits +=1 | |
for a in passwrd: | |
if (a.isupper()==True): | |
capital +=1 | |
for a in passwrd: | |
if (a.islower()==True): | |
lowercase +=1 | |
#Content display | |
print("------------------------------------------------------------------") | |
print("The generated password looks like this: "+ Fore.GREEN + passwrd + Fore.WHITE) | |
print ("It consists of: "+Fore.RED+ str(digits)+" digits"+Fore.WHITE+ ", "+Fore.YELLOW +str(capital)+" capital characters"+Fore.WHITE+ ", " + Fore.GREEN + str(lowercase) + " lower case characters" +Fore.WHITE+", and "+Fore.LIGHTMAGENTA_EX +str(passwrdlenght-(digits+capital+lowercase)) + " special characters"+ Fore.WHITE) | |
answer = ["n", "n", "n"] | |
#Questions | |
print("Do you want to generate a new password and discard this one? (y/n)") | |
answer[0] = input() | |
if (answer[0].lower() == "y"): | |
continue | |
print("Do you want to save this password in a txt file? (y/n)") | |
answer[1] = input() | |
print("Do you want quit the generator? (y/n)") | |
answer[2] = input() | |
#Question tasks | |
if (answer[1] == "y"): | |
fileSave("generated.txt", "a", passwrd, "Password") | |
print("Note: Password saved to \"generated.txt\"."+ Fore.RED + " DO NOT KEEP YOUR PASSWORDS SAVED HERE!" + Fore.WHITE) | |
if (answer[2] == "y"): | |
run = False | |
exit() | |
print("Press any button to continue...") | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment