Spaces:
Sleeping
Sleeping
File size: 6,537 Bytes
30dbb4d 9254410 cb9516b e23f48d 30dbb4d 019eb9c 2c71d6e cb9516b 2c71d6e 019eb9c 2c71d6e cb9516b 2c71d6e cb9516b e23f48d 2c71d6e 9254410 cb9516b 9254410 30dbb4d 2c71d6e 30dbb4d 2c71d6e cb9516b 019eb9c cb9516b 019eb9c cb9516b 019eb9c cb9516b 019eb9c 2c71d6e 019eb9c cb9516b 019eb9c cb9516b 30dbb4d 2c71d6e 30dbb4d 9254410 30dbb4d e23f48d 30dbb4d 2c71d6e 30dbb4d 2c71d6e e23f48d 30dbb4d 9254410 cb9516b 9254410 30dbb4d 53f3678 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# app.py
from flask import Flask, render_template, request, jsonify
from zxcvbn import zxcvbn
import os
app = Flask(__name__)
# ----------------------------------------------------------------------
# قاموس الترجمة (لحل مشكلة اللغة)
# ----------------------------------------------------------------------
TRANSLATIONS = {
# التحذيرات (Warnings)
"straight rows of keys are easy to guess": "الصفوف المستقيمة من الأحرف سهلة التخمين (مثل qwerty).",
"recent years are easy to guess": "السنوات الحديثة سهلة التخمين (لا تستخدم سنوات حديثة في كلمة المرور).",
"dates are easy to guess": "التواريخ سهلة التخمين.",
"top 10 common passwords": "كلمة المرور هذه ضمن أكثر 10 كلمات مرور شيوعاً في العالم.",
"top 100 common passwords": "كلمة المرور هذه ضمن أكثر 100 كلمة مرور شيوعاً.",
"very common password": "كلمة المرور هذه شائعة جداً.",
"names and surnames are easy to guess": "الأسماء والكنى (الألقاب) سهلة التخمين.",
"all-lowercase passwords are less secure": "كلمات المرور المكونة من أحرف صغيرة فقط أقل أماناً.",
"avoid repeated words and characters": "تجنب تكرار الكلمات والأحرف المتتالية.",
# النصائح (Suggestions)
"add another word or two": "أضف كلمة أو كلمتين إضافيتين (لزيادة الطول).",
"capitalize some letters": "استخدم الأحرف الكبيرة في بعض الكلمات (مثل: AlI).",
"add a symbol or two": "أضف رمزاً أو رمزين (مثل: # أو @).",
"all-lowercase is uncommon": "يفضّل مزج الأحرف الصغيرة والكبيرة.",
"avoid a sequence like 'abc'": "تجنب التسلسلات الشائعة مثل 'abc' أو '123'.",
"avoid repeated words": "تجنب تكرار الكلمات المتتالية.",
"avoid common typings like 'qwerty'": "تجنب أنماط الكتابة الشائعة مثل 'qwerty'.",
"use a few less common words": "استخدم كلمات أقل شيوعاً أو غير متوقعة.",
"add some numbers, symbols, or capitalization": "أضف بعض الأرقام أو الرموز أو استخدم الأحرف الكبيرة.",
"avoid dates and years": "تجنب استخدام التواريخ والسنوات.",
}
def translate_suggestion(text):
"""ترجمة النص من الإنجليزية إلى العربية باستخدام القاموس."""
# يتم البحث بالصيغة الصغيرة للكلمة مع إزالة المسافات البيضاء
return TRANSLATIONS.get(text.lower().strip(), text)
# ----------------------------------------------------------------------
# تحميل قائمة كلمات المرور المسربة
# ----------------------------------------------------------------------
LEAKED_PASSWORDS = set()
def load_leaked_passwords(file_path='leaked_passwords.txt'):
# ... (كود تحميل الملف يبقى كما هو)
if not os.path.exists(file_path):
print(f"⚠️ الملف {file_path} غير موجود. سيتم استخدام قائمة صغيرة للاختبار.")
return {"123456", "password", "كلمةسر", "محمد", "qwerty", "admin", "تيكتوك", "مرحبا123", "iloveyou"}
try:
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
LEAKED_PASSWORDS.add(line.strip().lower())
print(f"✅ تم تحميل {len(LEAKED_PASSWORDS)} كلمة مرور مسربة بنجاح.")
except Exception as e:
print(f"❌ حدث خطأ أثناء تحميل الملف: {e}. يتم استخدام قائمة الاختبار.")
return {"123456", "password"}
LEAKED_PASSWORDS = load_leaked_passwords()
# ----------------------------------------------------------------------
# 1. منطق تحليل قوة كلمة المرور الذكي (باستخدام zxcvbn)
# ----------------------------------------------------------------------
def check_password_strength(password):
is_leaked = password.lower() in LEAKED_PASSWORDS
if is_leaked:
status = "ضعيفة جداً"
color = "red"
percentage = 0
feedback = ["🚨 **خطر!** تم العثور عليها ضمن كلمات المرور المسربة أو الشائعة جداً."]
return status, color, feedback, percentage
results = zxcvbn(password)
zxcvbn_score = results['score']
percentage = int((zxcvbn_score / 4) * 100)
feedback = []
# ⚠️ تطبيق الترجمة على التحذيرات
if results['feedback']['warning']:
translated_warning = translate_suggestion(results['feedback']['warning'])
feedback.append(f"💡 تحذير: {translated_warning}")
# ⚠️ تطبيق الترجمة على النصائح
if results['feedback']['suggestions']:
translated_suggestions = [f"🌟 نصيحة: {translate_suggestion(s)}" for s in results['feedback']['suggestions']]
feedback.extend(translated_suggestions)
if zxcvbn_score >= 3:
status = "آمنة"
color = "green"
elif zxcvbn_score == 2:
status = "جيدة"
color = "orange"
else:
status = "ضعيفة"
color = "red"
return status, color, feedback, percentage
# ----------------------------------------------------------------------
# 2. مسارات تطبيق Flask
# ----------------------------------------------------------------------
@app.route('/')
def index():
return render_template('password-strength.html')
@app.route('/check', methods=['POST'])
def check():
data = request.get_json()
password = data.get('password', '')
status, color, feedback, percentage = check_password_strength(password)
return jsonify({
'status': status,
'color': color,
'feedback': feedback,
'percentage': percentage
})
# ----------------------------------------------------------------------
# 3. تشغيل التطبيق
# ----------------------------------------------------------------------
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True) |