حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

بررسی قدرت رمز عبور

تمرین آسان 205 visibility link download flag

برنامه‌ای بنویسید که رمز عبوری از کاربر دریافت کند و قدرت آن را بر اساس تعداد حروف بزرگ، حروف کوچک، اعداد و نویسه‌های خاص، به‌صورت «ضعیف»، «متوسط» یا «قوی» نمایش دهد.

رمز عبور باید حداقل ۸ نویسه داشته باشد و شامل دست‌کم یک عدد و یک حرف بزرگ باشد.

نمونهٔ ورودی و خروجی:

رمز عبور را وارد کنید: Amir@1234

قدرت رمز عبور: قوی
👨‍💻 8 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد
👨‍💻 7 ساعت قبل Amirdaneshfar این تمرین رو مشاهده کرد
👨‍💻 18 ساعت قبل User 11041 این تمرین رو مشاهده کرد

پاسخ‌ها 7

password = input("رمز عبور را وارد کنید: ")

has_upper = any(char.isupper() for char in password)
has_lower = any(char.islower() for char in password)
has_digit = any(char.isdigit() for char in password)
has_special = any(not char.isalnum() for char in password)

category_count = sum([has_upper, has_lower, has_digit, has_special])

if len(password) < 8 or not has_upper or not has_digit:
    strength = "ضعیف"
elif category_count == 4:
    strength = "قوی"
elif category_count == 3:
    strength = "متوسط"
else:
    strength = "ضعیف"

print(f"قدرت رمز عبور: {strength}")
پاسخ هوش مصنوعی Ai Python
password = input("Enter Your passwords : ")

strength = 0

has_upper = False
has_lower = False
has_digit = False
has_special = False

for char in password:
    if char.isupper():
        has_upper = True

    elif char.lower():
        has_lower = True

    elif char.has_digit():
        has_digit = True

    else:
        has_special = True

if len(password) >= 8 :
    strength += 1

if has_upper:
    strength += 1

if has_lower:
    strength += 1

if has_digit:
    strength += 1

if has_special:
    strength += 1

if strength <= 2:
    print("Password is weak.")

elif strength <= 4:
    print("Password is normal.")

else:
    print("Password is strong.")


def check_password_strength(password):
    """بررسی قدرت رمز عبور بدون استفاده از regex"""

    if len(password) < 8:
        return "ضعیف", "❌ رمز عبور باید حداقل ۸ نویسه داشته باشد."

    has_lower = any(c.islower() for c in password)
    has_upper = any(c.isupper() for c in password)
    has_digit = any(c.isdigit() for c in password)

    # نویسه‌های خاص
    special_chars = "!@#$%^&*(),.?\":{}|<>_-+=[]/\\;`~"
    has_special = any(c in special_chars for c in password)

    if not has_digit:
        return "ضعیف", "❌ رمز عبور باید حداقل یک عدد داشته باشد."
    if not has_upper:
        return "ضعیف", "❌ رمز عبور باید حداقل یک حرف بزرگ داشته باشد."

    score = sum([has_lower, has_upper, has_digit, has_special])

    if len(password) >= 12:
        score += 2
    elif len(password) >= 10:
        score += 1

    if score >= 6:
        return "قوی", "
password = input("رمز عبور را وارد کنید: ")

has_upper = any(char.isupper() for char in password)
has_lower = any(char.islower() for char in password)
has_digit = any(char.isdigit() for char in password)
has_special = any(not char.isalnum() for char in password)

category_count = sum([has_upper, has_lower, has_digit, has_special])

if len(password) < 8 or not has_upper or not has_digit:
    strength = "ضعیف"
elif category_count == 4:
    strength = "قوی"
elif category_count == 3:
    strength = "متوسط"
else:
    strength = "ضعیف"

print(f"قدرت رمز عبور: {strength}")
const readline = require("node:readline");

const readlineInterface = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

readlineInterface.question("رمز عبور را وارد کنید: ", (password) => {
  const hasUpper = /\p{Lu}/u.test(password);
  const hasLower = /\p{Ll}/u.test(password);
  const hasDigit = /\p{N}/u.test(password);
  const hasSpecial = /[^\p{L}\p{N}]/u.test(password);

  const categoryCount = [hasUpper, hasLower, hasDigit, hasSpecial]
    .filter(Boolean).length;

  let strength;

  if (password.length < 8 || !hasUpper || !hasDigit) {
    strength = "ضعیف";
  } else if (categoryCount === 4) {
    strength = "قوی";
  } else if (categoryCount === 3) {
    strength = "متوسط";
  } else {
    strength = "ضعیف";
  }

  console.log(`قدرت رمز عبور: ${strength}`);
  readlineInterface.close();
});
پاسخ هوش مصنوعی Ai JavaScript
user_name = input('user name? ')
password = input('enter your password plase: ')
if (
    len(password) >= 8
    and any(char.isdigit() for char in password)
    and any(char in "!@#$%^&*()" for char in password)
):
    print('yes very good')
else:print('رمز عبور ضعیف است یا تعداد کاراکتر  ها کمتر از 8 است')

#!/usr/bin/env bash

read -r -p "رمز عبور را وارد کنید: " password

has_upper=0
has_lower=0
has_digit=0
has_special=0

[[ $password =~ [[:upper:]] ]] && has_upper=1
[[ $password =~ [[:lower:]] ]] && has_lower=1
[[ $password =~ [[:digit:]] ]] && has_digit=1
[[ $password =~ [^[:alnum:]] ]] && has_special=1

category_count=$((has_upper + has_lower + has_digit + has_special))

if (( ${#password} < 8 || !has_upper || !has_digit )); then
    strength="ضعیف"
elif (( category_count == 4 )); then
    strength="قوی"
elif (( category_count == 3 )); then
    strength="متوسط"
else
    strength="ضعیف"
fi

printf 'قدرت رمز عبور: %s\n' "$strength"
پاسخ هوش مصنوعی Ai Bash

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن