// python projects

Password Checker in Python

The program defines a function, password_strength, that evaluates the strength of a provided password based on several criteria: length, presence of lowercase letters, uppercase letters, numbers, and special characters. It returns a string describing the password's strength as either 'Weak', 'Medium', or 'Strong'. When run as a standalone script, the program prompts the user to input a password and then displays the strength assessment of the entered password.

2021 1 min read pythonsecurity

The program defines a function, password_strength, that evaluates the strength of a provided password based on several criteria: length, presence of lowercase letters, uppercase letters, numbers, and special characters. It returns a string describing the password’s strength as either “Weak”, “Medium”, or “Strong”. When run as a standalone script, the program prompts the user to input a password and then displays the strength assessment of the entered password.

Password strength checker

Python script

import re

def password_strength(password):
    if len(password) < 8:
        return "Weak: Password is too short."

    if not re.search("[a-z]", password):
        return "Weak: Password should contain at least one lowercase letter."

    if not re.search("[A-Z]", password):
        return "Weak: Password should contain at least one uppercase letter."

    if not re.search("[0-9]", password):
        return "Weak: Password should contain at least one digit."

    special_characters = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
    if not special_characters.search(password):
        return "Medium: Password should contain at least one special character for stronger strength."

    return "Strong: Your password is strong."

if __name__ == "__main__":
    user_password = input("Enter your password: ")
    print(password_strength(user_password))