Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Password Strength
- #Copyright 2017 nihad ali
- def checkPass(password, pre_pass):
- length = int()
- lower = int()
- upper = int()
- special = int()
- number = int()
- like_past = int()
- f_name = int()
- s_name = int()
- password_strength = 0
- if len(password)>=8 :
- length = 1
- for i in lower_alphabet:
- if i in password:
- lower = 1
- for i in upper_alphabet:
- if i in password:
- upper = 1
- for i in special_characters:
- if i in password:
- special = 1
- for i in numbers:
- if i in password:
- number = 1
- if pre_pass.lower() not in password.lower():
- like_past = 1
- if length == 1:
- password_strength += 1
- if lower == 1 :
- password_strength += 1
- if upper== 1 :
- password_strength += 1
- if special == 1:
- password_strength +=2
- if f_name != 1:
- password_strength -=2
- if s_name != 1:
- password_strength -=2
- if like_past != 1:
- password_strength -=1
- password_rank = str()
- if password_strength >= 5:
- password_rank = 'Very Strong'
- elif password_strength == 4:
- password_rank = 'Strong'
- elif password_strength == 3:
- password_rank = 'OK'
- elif password_strength == 2:
- password_rank = 'Not Good'
- elif password_strength ==1:
- password_rank = 'Bad'
- elif password_strength < 1:
- password_rank = 'very bad'
- print('\nI think that your password is ',password_rank)
- issues = [length, lower, upper, special, number, like_past, f_name, s_name, password_rank]
- return issues
- lower_alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
- upper_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
- numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
- special_characters = [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]
- choice = None
- print("""
- Welcome to Nihad's password strength tester
- """)
- while choice != '0':
- print("""
- Menu options:
- 1 - Password Generator
- 2 - Check Password Strength
- 3 - quit
- """)
- choice = str(input('Please type the number that is beside your choice and press enter: '))
- if choice == '1':
- password = input('\nPlease enter your password here: ')
- pre_pass = input('\nPlease enter your old password here: ')
- issues = checkPass(password,pre_pass)
- why = input('\nIf you would like to find out why type why? and press enter: ')
- if why.lower() == 'why?':
- if issues[0] != 1:
- print("It's too short")
- if issues[1] != 1:
- print("It doesn't have a lower case character in it")
- if issues[2] != 1:
- print("It doesn't have an upper case character in it")
- if issues[3] != 1:
- print("It doesn't have a special character in it")
- if issues[4] != 1:
- print("It doesn't have a number in it")
- if issues[5] != 1:
- print("It's like your old password")
- if issues[6] != 1:
- print("It's got your first name in it")
- if issues[7] != 1:
- print("It's got your last name in it")
- if issues[8] == 'Very Strong':
- print('There is nothing wrong with it!')
- elif choice == '0':
- print('Check your password strength here')
- else:
- print('Goodbye')
- from sys import exit
- def check_upper(input):
- uppers = 0
- upper_list = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split()
- for char in input:
- if char in upper_list:
- uppers += 1
- if uppers > 0:
- return True
- else:
- return False
- def check_lower(input):
- lowers = 0
- lower_list = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split()
- for char in input:
- if char in lower_list:
- lowers += 1
- if lowers > 0:
- return True
- else:
- return False
- def check_number(input):
- numbers = 0
- number_list = "1 2 3 4 5 6 7 8 9 0".split()
- for char in input:
- if char in number_list:
- numbers += 1
- if numbers > 0:
- return True
- else:
- return False
- def check_special(input):
- specials = 0
- special_list = "! @ $ % ^ & * ( ) _ - + = { } [ ] | \ , . > < / ? ~ ` \" ' : ;".split()
- for char in input:
- if char in special_list:
- specials += 1
- if specials > 0:
- return True
- else:
- return False
- def check_len(input):
- if len(input) >= 8:
- return True
- else:
- return False
- def validate_password(input):
- check_dict = {
- 'upper': check_upper(input),
- 'lower': check_lower(input),
- 'number': check_number(input),
- 'special': check_special(input),
- 'len' : check_len(input)
- }
- if check_upper(input) & check_lower(input) & check_number(input) & check_special(input) & check_len(input):
- return True
- else:
- print ("Invalid password! Review below and change your password accordingly!")
- print
- if check_dict['upper'] == False:
- print ("Password needs at least one upper-case character.")
- if check_dict['lower'] == False:
- print ("Password needs at least one lower-case character.")
- if check_dict['number'] == False:
- print ("Password needs at least one number.")
- if check_dict['special'] == False:
- print ("Password needs at least one special character.")
- if check_dict['len'] == False:
- print ("Password needs to be at least 8 characters in length.")
- print
- while True:
- password = input ("Enter desired password: ")
- print
- if validate_password(password):
- print ("Password meets all requirements and may be used.")
- print
- print ("Exiting program...")
- print
- exit(0)
Add Comment
Please, Sign In to add comment