Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Intro
- print("*******************************************************************************************************")
- print("*******************************************************************************************************")
- print("Welcome to PasswordCreation Programme. To create your password, you have to follow the following rules: ")
- print("1. Your password length must be at least 8 characters.")
- print("2. Your password must contain at least 1 lowerCase letter.")
- print("3. Your password must contain at least 1 upperCase letter.")
- print("4. Your password must contain at least l number.")
- print("5. Your password must not contain 'Spacebar' character.")
- print("6. Your password must not contain special characters.")
- print()
- print("Then, you will have to confirm your password.")
- print("Please enter your password: ")
- # Ask from the user to give me his string/password
- password = input()
- lowerAlphabet = "abcdefghijklmnopqrstuvwxyz"
- upperAlphabet = lowerAlphabet.upper()
- numbers = "1234567890"
- # Create 6 basic variables for checking the 4 terms and 1 variable to count how many conditions are satisfied
- lowerCounter = 0 # Condition 2
- upperCounter = 0 # Condition 3
- numberCounter = 0 # Condition 4
- spacebarFlag = False # Condition 5
- specialCharactersFlag = False # Condition 6
- specialCharacters = [] # Create a list, that will contain all the special characters of password
- conditionsSatisfied = True # Boolean value for checking if the conditions for a valid password are satisfied (Initially, I suppose it's true)
- # Scan the password and investigate the conditions
- length = len(password)
- for ch in password:
- # For every character in user's password, I check the 1st condition/rule
- if ch in lowerAlphabet: # Ayto shmainei an to ch = character anhkei stin "lexi" lowerAlphabet
- lowerCounter += 1
- elif ch in upperAlphabet:
- upperCounter +=1
- elif ch in numbers:
- numberCounter += 1
- elif ch == ' ':
- spacebarFlag = True
- else:
- specialCharactersFlag = True
- specialCharacters.append(ch) # I add the special character "ch" to the appropriate list
- # So, I have some values on my variables
- # I will compare these values with my conditions/rules
- # 1st check
- if len(password) < 8:
- conditionsSatisfied = False
- if lowerCounter == 0:
- conditionsSatisfied = False
- if upperCounter == 0:
- conditionsSatisfied = False
- if numberCounter == 0:
- conditionsSatisfied = False
- if spacebarFlag:
- conditionsSatisfied = False # If spacebarFlag == True, that means that password contains a spacebar ---> not a valid password
- if specialCharactersFlag:
- conditionsSatisfied = False
- # All the conditions have been checked. THE RESULTS OF INVESTIGATIONS WILL BE PRINTED ON THE SCREEN BELOW
- print()
- # IF PASSWORD = INVALID
- if not conditionsSatisfied:
- #print()
- print("Not a valid password. Problems with password: " + password)
- # Here, I will explain in which parts the password has problem
- if len(password) < 8:
- print("* Length = " + str(len(password)))
- if lowerCounter == 0:
- print("* No lowerCase letters in the password.")
- if upperCounter == 0:
- print("* No upperCase letters in the password.")
- if numberCounter == 0:
- print("* No number used in the password.")
- if spacebarFlag:
- print("* Your password contains the 'Spacebar' character.")
- if specialCharactersFlag:
- print("* Your password contains special characters: " + ''.join(map(str, specialCharacters)))
- # IF PASSWORD = VALID
- else:
- print("That's a valid password. Please confirm this password. You will have only 3 tries.")
- confirmationTries = 0
- while confirmationTries < 3: # Loop with max number of iterations = max tries = 3
- passwordConfirmation = input("Confirm password here: ") # Ask from the user the password confirmation
- if password != passwordConfirmation: # If passwordConfirmation not equal to password, I increase the confirmationTries variable
- confirmationTries += 1
- else: # If passwordConfirmation equal to password, WE ARE OKEY!
- print("Brilliant. Your new password is: " + password)
- break
- if confirmationTries == 3: # If we are in the case of wasting both 3 tries
- print()
- print("Password creation failed (you ran out of tries): ")
- print("You entered the password : " + password)
- print("But, your last confirmation was: " + passwordConfirmation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement