Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- while True:
- def Check_password(password):
- global strength, score #Makes the varirable "strength" and "score" accessable to the entire program
- while len(password) < 8 or len(password) > 24:
- print('Please re-enter password and make sure your password is between 8 and 24 characters\n')
- Menu()
- score = len(password)
- password_array = list(password) #Putting password into a array
- password_ascii = list()
- for i in range (len(password)):#For loop assigning ascii values of password into a array
- password_ascii.append(ord(password[i]))
- capital_letter = False
- lowercase_letter = False
- number = False
- symbol = False
- for i in range (len(password)):
- if password_ascii[i] >= 65 and password_ascii[i] <= 90:#Checking for capital letters using ascii
- capital_letter = True
- if password_ascii[i] >= 97 and password_ascii[i] <= 122:#Checking for lowercase letters using ascii
- lowercase_letter = True
- if password_ascii[i] >= 48 and password_ascii[i] <= 57:#Checking for numbers 0-9 using ascii
- number = True
- if password_ascii[i] == 33 or password_ascii[i] == 45 or password_ascii[i] == 61:#Checking for symbols using ascii
- symbol = True
- if password_ascii[i] >= 36 and password_ascii[i] <= 38:
- symbol = True
- if password_ascii[i] >= 40 and password_ascii[i] <= 43:
- symbol = True
- if password_ascii[i] == 94 or password_ascii[i] == 95:
- symbol = True
- if capital_letter == False and lowercase_letter == False and number == False and symbol == False:#Checking that the password only contains valid character
- print('You entered an invalid character\n You will be returned to the menu')
- Menu()
- #Checking for QWERTY
- password_lowercase = password.lower() # Puts password into all lowercsse
- #Checking foe the first row of qwerty
- qwerty_1st = "qwertyuiop"
- for i in range(0, len(password_lowercase) - 2):
- check = password_lowercase[i:i + 3]
- if check in qwerty_1st:
- score -= 5
- #Checking for the second row of qwerty
- qwerty_2nd = "asdfghjkl"
- for i in range(0, len(password_lowercase) - 2):
- check = password_lowercase[i:i + 3]
- if check in qwerty_2nd:
- score -= 5
- #Checking for the third row of qwerty
- qwerty_3rd = "zxcvbnm"
- for i in range(0, len(password_lowercase) - 2):
- check = password_lowercase[i:i + 3]
- if check in qwerty_3rd:
- score -= 5
- #Adding up the score from the checks
- if capital_letter == True:#Adding 5 points to the password if at least on capital letter
- score += 5
- if lowercase_letter == True:#Adding 5 points to the password if lowercase letters are present
- score += 5
- if number == True:#Adding up the score if numbers are in the password
- score += 5
- if symbol == True:#Adding 5 points if the allowed symbols are in the password
- score += 5
- if capital_letter == True and lowercase_letter == True and number == True and symbol == True:#Adding 10 points if the password contains capital letter
- score += 10
- if capital_letter == True or lowercase_letter == True and number == False and symbol == False:#Taking 5 points if it only conaints capital and lowercase letters
- score -= 5
- elif capital_letter == False and lowercase_letter == False and number == True and symbol == False:#Taking 5 points if it only have numbers in
- score -= 5
- elif capital_letter == False and lowercase_letter == False and number == False and symbol == True:#Taking 5 points if it only has symbols in
- score -= 5
- #Determining the passwords strength
- strength = ''
- if score > 20:
- strength = 'Strong'
- elif score <= 0:
- strength = 'Weak'
- else:
- strength = 'Medium'
- print('Your password,',password+', has a strength of:',strength,'\nYou will now be returned to the menu')
- Menu()
- def Generate_password():
- global score #Makes variable "score" accessable to the whole program
- length = random.randint(9,24)
- password_generated_array = [None]*length
- characters = [['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'], #Multidimensional array containing all characters
- ['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'], #needed for the password generation
- ['0','1','2','3','4','5','6','7','8','9'],
- ['!','$','%','^','&','*','(',')','-','_','=','+']]
- for i in range (length): #For loop to assign each character to the password array
- character_choice = random.randint(0,len(characters))
- character_choice_2 = random.randint(0,len(characters[character_choice - 1]))
- password_generated_array[i] = characters[character_choice - 1][character_choice_2 - 1]
- password_generated = ''.join(password_generated_array) #Converting the array back into a string
- Check_password(password_generated)
- def Menu():
- print('Please selection on of the following options:')
- option = int(input("**********************\n1. Check Password\n2. Generate password\n3. Quit\n**********************\n"))
- if option == 1:
- password = input('Please enter your password\n')
- Check_password(password)
- elif option == 2:
- Generate_password()
- elif option == 3:
- quit()
- Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement