# 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)