Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Password generator and strength Checker
- from random import choice, randint
- from string import ascii_letters as letters
- programmRunning = True
- symbols = '!$%^&*()_-=+'
- points = 0
- # 2 Strength checker
- def strengthCheck(x):
- global points
- points = 0
- hasall = 0
- # Points for length of password
- points = points + len(x)
- # Upper case letters
- if (any(i.isupper() for i in x)) == True:
- points += 5
- hasall+= 1
- # Lower case letters
- if (any(i.islower() for i in x)) == True:
- points += 5
- hasall+= 1
- # Checking for symbols
- if any((c in symbols) for c in x):
- points += 5
- hasall += 1
- # Checking for numbers
- if (any(i.isdigit() for i in x)) == True:
- points += 5
- hasall+= 1
- if hasall == 4:
- points += 10
- # Checking if only contains symbols
- if (any(i.islower() for i in x)) == False and (any(i.isupper() for i in x)) == False :
- points -= 5
- # Checking if only contains numbers
- if (any(i.isalpha() for i in x)) == False:
- points -= 5
- # Checking if only contains uppercase and lowercase
- if (any(i.isdigit() for i in x)) == False:
- points -= 5
- # Check for any consecutive letters
- lines = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
- triples = []
- for line in lines:
- for i in range(len(line)-2):
- triples.append(line[i:i+3])
- # This lowers all string characters to lowercase
- loweredx = []
- for i in x:
- if i.isupper() == True:
- loweredx.append(i.lower())
- elif i.islower() == True:
- loweredx.append(i)
- elif i.isdigit() == True:
- loweredx.append(i)
- elif i in symbols:
- loweredx.append(i)
- x = ''.join(loweredx) # converts above list to string
- # search for each occurance of a triple
- triple_count = 0
- for i in triples:
- if i in x:
- triple_count += 1
- points = points - (triple_count*5)
- if triple_count >0:
- print("number of triple occurances ", triple_count)
- # Judging whether pass is W, M or s
- if points <=0:
- print("Password: %s is weak. %i points" % (x, points))
- elif points >20:
- print("Password: %s is strong. %i points" % (x, points))
- else:
- print("Password: %s is medium. %i points" % (x, points))
- def inputPassword():
- checkPW = input("Please enter a password to check its strength: ")
- strengthCheck(checkPW)
- # 3 Password Generator
- def generatePW():
- lengthofPW = randint(8,12)
- print("The Length of your password is: %i characters" % (lengthofPW))
- while points < 20:
- newPW = []
- for i in range(lengthofPW):
- choiceOfCharacter = randint(1,3)
- if choiceOfCharacter == 1:
- y = randint(0,9)
- newPW.append(str(y))
- elif choiceOfCharacter == 2:
- y = choice(letters)
- newPW.append(y)
- elif choiceOfCharacter == 3:
- randomSymbol = randint(0, 11)
- y = symbols[randomSymbol]
- newPW.append(y)
- newPW = ''.join(newPW)
- strengthCheck(newPW)
- while programmRunning == True:
- # 1 Menu
- print('''
- Password Strength Checker & Generator
- Please choose from one of the following options
- 1. Check Password
- 2. Generate a Password
- 3. Quit
- ''')
- userchoice = int(input("\n>o>"))
- if userchoice == 1:
- inputPassword()
- elif userchoice == 2:
- points = 0
- generatePW()
- elif userchoice == 3:
- programmRunning = False
- print("You may now close the programme window.")
- else:
- print("You have made an invalid choice!")
Add Comment
Please, Sign In to add comment