Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def menu():
- getmenuchoice = True
- while getmenuchoice == True:
- print("1. Check Password")
- print("2. Generate Password")
- print("3. Quit")
- menuchoice = str(input("Please input your choice: "))
- if menuchoice.isdigit():
- getmenuchoice = False
- else:
- print("Please input a valid choice")
- print("Hint: Just input the number of your choice")
- if menuchoice == "1":
- print("Running Checking Password Function")
- print("----------------------------------")
- checkingpassword()
- elif menuchoice == "2":
- print("Running Generate Password Function")
- print("----------------------------------")
- generatepassword()
- elif menuchoice == "3":
- quit()
- else:
- print("Please input a valid choice")
- menu()
- def checkingpassword():
- userpassword = input("Input your password: ")
- passwordlength = len(userpassword)
- allowedsymbols = ["!","$","%","^","&","*","(",")","-","_","=","+"]
- upperfound = False
- lowerfound = False
- digitfound = False
- symbolfound = False
- import re
- spaceError = re.search(r's',userpassword) is None
- if spaceError != True:
- print("Invalid Password")
- menu()
- if passwordlength < 8 or passwordlength > 24:
- print("Invalid Password")
- menu()
- else:
- for char in userpassword:
- if char.isupper():
- upperfound = True
- if char.islower():
- lowerfound = True
- if char.isdigit():
- digitfound = True
- if char in allowedsymbols:
- symbolfound = True
- if upperfound == False and lowerfound == False and digitfound == False and symbolfound == False:
- print("Your password contains a character that is not allowed")
- menu()
- else:
- callscore = scoring(userpassword,upperfound,lowerfound,digitfound,allowedsymbols,passwordlength)
- return callscore
- def scoring(userpassword,upperfound,lowerfound,digitfound,symbolfound,passwordlength):
- allowedrow1 = "qwertyuiop"
- allowedrow2 = "asdfghjkl"
- allowedrow3 = "zxcvbnm"
- points = 0
- counter = 0
- #adding points
- points += passwordlength
- print("+"+ str(passwordlength) + " for the length")
- if upperfound == True:
- points += 5
- print("+5 for having uppercase")
- if lowerfound == True:
- points += 5
- print("+5 for having lowercase")
- if digitfound == True:
- points += 5
- print("+5 for having digits")
- if symbolfound == True:
- points += 5
- print("+5 for having symbols")
- if upperfound == True and lowerfound == True and digitfound == True and symbolfound == True:
- points += 10
- print("+10 for having everything")
- #subtracting points
- if lowerfound == True and upperfound == False and digitfound == False and symbolfound == False:
- points -= 5
- print("-5 for only having lowercase")
- if upperfound == True and upperfound == False and digitfound == False and symbolfound == False:
- points -= 5
- print("-5 for only having uppercase")
- if digitfound == True and upperfound == False and lowerfound == False and symbolfound == False:
- points -= 5
- print("-5 for only having digits")
- if symbolfound == True and upperfound == False and lowerfound == False and digitfound == False:
- points -= 5
- print("+5 for only having symbols")
- #subtracting three consecutive letters
- for position in range(0,len(userpassword)-2):
- posi = userpassword[position : position + 3]
- if posi.lower() in allowedrow1 :
- counter += 1
- if posi.lower() in allowedrow2 :
- counter += 1
- if posi.lower() in allowedrow3 :
- counter += 1
- points = points - (counter * 5)
- strength = passwordstrength(points)
- return strength
Add Comment
Please, Sign In to add comment