Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def print_menu():
- print( 30 * "-" , "MENU" , 30 * "-")
- print("1. Check password strength")
- print("2. Generate an ideal password")
- print("3. Quit")
- print( 67 * "-")
- def genpass():
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- symbols = "!$%^&*()-_=+"
- upperalphabet = alphabet.upper()
- pw_len = 12
- pwlist = []
- for i in range(pw_len//3):
- pwlist.append(alphabet[random.randrange(len(alphabet))])
- pwlist.append(symbols[random.randrange(len(symbols))])
- pwlist.append(upperalphabet[random.randrange(len(upperalphabet))])
- pwlist.append(str(random.randrange(10)))
- for i in range(pw_len-len(pwlist)):
- pwlist.append(alphabet[random.randrange(len(alphabet))])
- random.shuffle(pwlist)
- pwstring = "".join(pwlist)
- print(pwstring)
- def passcheck():
- password_user = input("Input password : ")
- score = 0
- if len(password_user) <=5:
- print("Password is too short! ")
- score = 1
- elif password_user == password_user.lower():
- print("Bad Password")
- score = 1
- elif password_user == password_user.upper():
- print("Bad Password")
- score = 1
- else:
- while score == 0:
- for x in range(33,48):
- ascii_str = chr(x)
- if password_user.find(ascii_str) >= 0:
- score = score + 3
- for y in range(97,123):
- ascii_lower = chr(y)
- if password_user.find(ascii_lower) >= 0:
- score = score + 1
- for w in range(65,91):
- ascii_upper = chr(w)
- if password_user.find(ascii_upper) >= 0:
- score = score + 2
- for z in range(48,58):
- ascii_num = chr(z)
- if password_user.find(ascii_num) >= 0:
- score = score + 2
- if score >0 | score <=5:
- print("Weak Password")
- print(score)
- elif score > 5 | score < 7:
- print("Medium Password")
- print(score)
- elif score >= 7:
- print("Strong Password")
- print(score)
- loop=True
- while loop:
- print_menu()
- choice = input("Enter your choice [1-3]:")
- if choice==("1"):
- print("You have chosen to check your password strenth")
- loop=False
- passcheck()
- elif choice==("2"):
- print("You have chosen to generate an ideal password")
- loop=False
- genpass()
- elif choice==("3"):
- print("You have chosen to exit")
- loop=False
- else:
- input("Wrong selection. Enter a number between 1 and 3")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement