Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Check Password Strength | Introduction to Cyber Security
Cyber Security Fundamentals

book
Challenge: Check Password Strength

Now, let's create a simple program to assess the strength of a password. As we've emphasized earlier, having a robust password is crucial for protection against malware and phishing attempts. So, let's proceed with building our straightforward program!

Завдання

Swipe to start coding

You have to write a function that checks the strength of the password. Password is considered strong if it has more than 8 characters and there is at least one number and at least one letter.

  1. Use < operator to check if the provided password has more than 8 characters.
  2. Use .search() method of re library to check if there is at least one number and at least one number.

Note

re is the abbreviation for the "regular expression" module in Python. It provides powerful tools for pattern matching and text manipulation. If you want to have more practice with these expressions, you can try our Regex Wizards project.

Once you've completed this task, click the button below the code to check your solution.

Рішення

import re

def check_password_strength(password):
# Check if password has at least 8 characters
if len(password) < 8:
return False
# Check if password contains at least one letter and one number
if not re.search(r'[a-zA-Z]', password) or not re.search(r'\d', password):
return False
return True

# Example usage:
password_to_check = "SecureP@ssw0rd"
if check_password_strength(password_to_check):
print("Password is strong!")
else:
print("Password does not meet the criteria.")

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6
import re

def check_password_strength(password):
# Check if password has at least 8 characters
if len(password) ___ 8:
return False
# Check if password contains at least one letter and one number
if not re.___(r'[a-zA-Z]', password) or not re.___(r'\d', password):
return False
return True

# Example usage:
password_to_check = "SecureP@ssw0rd"
if check_password_strength(password_to_check):
print("Password is strong!")
else:
print("Password does not meet the criteria.")
toggle bottom row
some-alt