Spaces:
Sleeping
Sleeping
| # app.py | |
| from flask import Flask, render_template, request, jsonify | |
| from password_data import COMMON_PASSWORDS | |
| import re | |
| app = Flask(__name__) | |
| # ---------------------------------------------------------------------- | |
| # 1. منطق تحليل قوة كلمة المرور والتحقق من التسريب | |
| # ---------------------------------------------------------------------- | |
| def check_password_strength(password): | |
| """ | |
| تحليل قوة كلمة المرور وإرجاع الحالة والنصائح. | |
| يعتمد على قواعد (AI Rule-based). | |
| """ | |
| score = 0 | |
| feedback = [] | |
| # أ. قواعد قوة كلمة المرور | |
| if len(password) >= 12: | |
| score += 3 | |
| feedback.append("✔️ طول ممتاز (12 حرفًا أو أكثر).") | |
| elif len(password) >= 8: | |
| score += 2 | |
| feedback.append("⭐ طول جيد (8-11 حرفًا).") | |
| else: | |
| feedback.append("❌ كلمة المرور قصيرة جداً (يجب أن تكون 8 أحرف على الأقل).") | |
| if re.search(r"[a-z]", password): score += 1 # أحرف إنجليزية صغيرة | |
| if re.search(r"[A-Z]", password): score += 1 # أحرف إنجليزية كبيرة | |
| if re.search(r"\d", password): score += 1 # أرقام | |
| # دعم الأحرف العربية والرموز | |
| if re.search(r"[^a-zA-Z0-9\s]", password): | |
| score += 1 | |
| # ب. التحقق من التسريب (محاكاة بيانات Hugging Face) | |
| is_leaked = password.lower() in [p.lower() for p in COMMON_PASSWORDS] | |
| if is_leaked: | |
| status = "ضعيفة جداً" | |
| color = "red" | |
| feedback.append("🚨 **خطر!** تم العثور عليها ضمن كلمات المرور المسربة أو الشائعة جداً.") | |
| elif score >= 5: | |
| status = "آمنة" | |
| color = "green" | |
| elif score >= 3: | |
| status = "جيدة" | |
| color = "orange" | |
| else: | |
| status = "ضعيفة" | |
| color = "red" | |
| return status, color, feedback | |
| # ---------------------------------------------------------------------- | |
| # 2. مسارات تطبيق Flask | |
| # ---------------------------------------------------------------------- | |
| def index(): | |
| """مسار عرض الواجهة الأمامية.""" | |
| return render_template('index.html') | |
| def check(): | |
| """مسار فحص كلمة المرور واسترجاع النتائج.""" | |
| data = request.get_json() | |
| password = data.get('password', '') | |
| status, color, feedback = check_password_strength(password) | |
| return jsonify({ | |
| 'status': status, | |
| 'color': color, | |
| 'feedback': feedback | |
| }) | |
| # ---------------------------------------------------------------------- | |
| # 3. تشغيل التطبيق (مع التعديل الضروري) | |
| # ---------------------------------------------------------------------- | |
| if __name__ == '__main__': | |
| # **التعديل الهام:** تحديد المضيف (host) على '0.0.0.0' | |
| # هذا يحل مشكلة 'رفض الاتصال' عند العمل على خوادم الاستضافة الخارجية. | |
| app.run(host='0.0.0.0', debug=True) |