Skip to content

added a script that checks password strength from 1 to 5 i.e weak to … #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions PASSWORD RELATED/password-strength/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Password Strength Checker

This is a simple Python script that checks the strength of a given password based on various criteria. It evaluates the password for length, lowercase letters, uppercase letters, digits, and special characters, and provides feedback on its strength.

## How to Use

1. Clone the repository or download the script file `password_strength_checker.py`.

2. Run the script using Python (Python 3.x is recommended).

3. Enter the password you want to check when prompted.

4. The script will evaluate the password and display its strength along with any areas of improvement.

## Criteria for Password Strength

The password is evaluated against the following criteria:

- Minimum password length: The password should have at least 8 characters.

- At least one lowercase letter: The password should contain at least one lowercase letter (a-z).

- At least one uppercase letter: The password should contain at least one uppercase letter (A-Z).

- At least one digit: The password should contain at least one digit (0-9).

- At least one special character: The password should contain at least one special character (!@#$%^&*()_+=-[]{};:'",.<>?/\\|).

## Password Strength Scores

The password is given a strength score based on the number of criteria met:

- 1: Weak - The password does not meet the minimum length requirement.

- 2: Moderate - The password meets the minimum length requirement but lacks some character types.

- 3: Fair - The password meets the minimum length requirement and includes lowercase letters, uppercase letters, and digits.

- 4: Strong - The password meets the minimum length requirement and includes lowercase letters, uppercase letters, digits, and at least one special character.

- 5: Very Strong - The password meets all criteria and is considered very strong.

## Example

```bash
$ python password_strength_checker.py
Enter your password: My$3cureP@ssw0rd

Password Strength: 5
Password is very strong!
```

## Customization

You can customize the min_length variable in the script to set your desired minimum password length.

Feel free to modify and enhance the script according to your needs and security requirements.
58 changes: 58 additions & 0 deletions PASSWORD RELATED/password-strength/password_strength_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import re


def password_strength(password):
"""
Checks the strength of a password and returns a tuple containing the strength
"""
# Minimum password length
min_length = 8

# Regular expressions to check for different character types
has_lowercase = re.compile(r'[a-z]')
has_uppercase = re.compile(r'[A-Z]')
has_digit = re.compile(r'\d')
has_special = re.compile(r'[!@#$%^&*()_+=\-[\]{};:\'",.<>?/\\|]')

strength = 0
messages = []

if len(password) >= min_length:
strength += 1
else:
messages.append("Password should have at least {} characters.".format(min_length))

if has_lowercase.search(password):
strength += 1
else:
messages.append("Password should have at least one lowercase letter.")

if has_uppercase.search(password):
strength += 1
else:
messages.append("Password should have at least one uppercase letter.")

if has_digit.search(password):
strength += 1
else:
messages.append("Password should have at least one digit.")

if has_special.search(password):
strength += 1
else:
messages.append("Password should have at least one special character.")

return strength, messages


if __name__ == "__main__":
password = input("Enter your password: ")
strength, messages = password_strength(password)

print("\nPassword Strength: {}".format(strength))
if strength == 5:
print("Password is very strong!")
else:
print("Password needs improvement:")
for message in messages:
print("- {}".format(message))