Skydata001 commited on
Commit
9254410
·
verified ·
1 Parent(s): efab5e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -1,24 +1,24 @@
1
  # app.py
2
 
3
- # 1. استيراد المكتبات الأساسية
4
- from flask import Flask, render_template, request, jsonify # Flask لإدارة الويب
5
- from password_data import COMMON_PASSWORDS # ملف البيانات المحلي (محاكاة بيانات التسريب)
6
- import re # مكتبة التعبيرات النمطية لفحص أنواع الأحرف
7
 
8
- # تهيئة تطبيق Flask
9
  app = Flask(__name__)
10
 
11
- # دالة (Function) لفحص القوة والتحقق من التسريب
 
 
 
12
  def check_password_strength(password):
13
- """تحليل قوة كلمة المرور وإرجاع الحالة والنصائح."""
 
 
 
14
  score = 0
15
  feedback = []
16
 
17
- # ------------------
18
  # أ. قواعد قوة كلمة المرور
19
- # ------------------
20
-
21
- # القاعدة 1: الطول (الأولوية القصوى)
22
  if len(password) >= 12:
23
  score += 3
24
  feedback.append("✔️ طول ممتاز (12 حرفًا أو أكثر).")
@@ -28,28 +28,21 @@ def check_password_strength(password):
28
  else:
29
  feedback.append("❌ كلمة المرور قصيرة جداً (يجب أن تكون 8 أحرف على الأقل).")
30
 
31
- # القاعدة 2: تنوع الأحرف (نقاط إضافية لكل نوع)
32
  if re.search(r"[a-z]", password): score += 1 # أحرف إنجليزية صغيرة
33
  if re.search(r"[A-Z]", password): score += 1 # أحرف إنجليزية كبيرة
34
  if re.search(r"\d", password): score += 1 # أرقام
35
 
36
- # القاعدة 3: الرموز والأحرف العربية
37
- # هذا التعبير يبحث عن أي شيء ليس حرفاً إنجليزياً أو رقم، بما في ذلك الرموز والأحرف العربية.
38
  if re.search(r"[^a-zA-Z0-9\s]", password):
39
  score += 1
40
 
41
- # ------------------
42
- # ب. التحقق من التسريب (محاكاة Hugging Face)
43
- # ------------------
44
-
45
- # تحويل الكل إلى أحرف صغيرة للمقارنة غير الحساسة لحالة الأحرف
46
  is_leaked = password.lower() in [p.lower() for p in COMMON_PASSWORDS]
47
 
48
  if is_leaked:
49
- # إذا كانت مسربة، يتم إهمال القوة وتصنيفها كـ "ضعيفة جداً"
50
  status = "ضعيفة جداً"
51
  color = "red"
52
- feedback.append("🚨 تم العثور عليها ضمن كلمات المرور المسربة أو الشائعة جداً.")
53
  elif score >= 5:
54
  status = "آمنة"
55
  color = "green"
@@ -62,26 +55,34 @@ def check_password_strength(password):
62
 
63
  return status, color, feedback
64
 
65
- # مسار الصفحة الرئيسية: عرض الواجهة
 
 
 
66
  @app.route('/')
67
  def index():
 
68
  return render_template('index.html')
69
 
70
- # مسار الفحص: استقبال كلمة المرور وإرسال النتيجة
71
  @app.route('/check', methods=['POST'])
72
  def check():
 
73
  data = request.get_json()
74
  password = data.get('password', '')
75
 
76
  status, color, feedback = check_password_strength(password)
77
 
78
- # إرجاع النتائج بتنسيق JSON
79
  return jsonify({
80
  'status': status,
81
  'color': color,
82
  'feedback': feedback
83
  })
84
 
 
 
 
 
85
  if __name__ == '__main__':
86
- # تشغيل التطبيق في وضع التطوير
87
- app.run(debug=True)
 
 
1
  # app.py
2
 
3
+ from flask import Flask, render_template, request, jsonify
4
+ from password_data import COMMON_PASSWORDS
5
+ import re
 
6
 
 
7
  app = Flask(__name__)
8
 
9
+ # ----------------------------------------------------------------------
10
+ # 1. منطق تحليل قوة كلمة المرور والتحقق من التسريب
11
+ # ----------------------------------------------------------------------
12
+
13
  def check_password_strength(password):
14
+ """
15
+ تحليل قوة كلمة المرور وإرجاع الحالة والنصائح.
16
+ يعتمد على قواعد (AI Rule-based).
17
+ """
18
  score = 0
19
  feedback = []
20
 
 
21
  # أ. قواعد قوة كلمة المرور
 
 
 
22
  if len(password) >= 12:
23
  score += 3
24
  feedback.append("✔️ طول ممتاز (12 حرفًا أو أكثر).")
 
28
  else:
29
  feedback.append("❌ كلمة المرور قصيرة جداً (يجب أن تكون 8 أحرف على الأقل).")
30
 
 
31
  if re.search(r"[a-z]", password): score += 1 # أحرف إنجليزية صغيرة
32
  if re.search(r"[A-Z]", password): score += 1 # أحرف إنجليزية كبيرة
33
  if re.search(r"\d", password): score += 1 # أرقام
34
 
35
+ # دعم الأحرف العربية والرموز
 
36
  if re.search(r"[^a-zA-Z0-9\s]", password):
37
  score += 1
38
 
39
+ # ب. التحقق من التسريب (محاكاة بيانات Hugging Face)
 
 
 
 
40
  is_leaked = password.lower() in [p.lower() for p in COMMON_PASSWORDS]
41
 
42
  if is_leaked:
 
43
  status = "ضعيفة جداً"
44
  color = "red"
45
+ feedback.append("🚨 **خطر!** تم العثور عليها ضمن كلمات المرور المسربة أو الشائعة جداً.")
46
  elif score >= 5:
47
  status = "آمنة"
48
  color = "green"
 
55
 
56
  return status, color, feedback
57
 
58
+ # ----------------------------------------------------------------------
59
+ # 2. مسارات تطبيق Flask
60
+ # ----------------------------------------------------------------------
61
+
62
  @app.route('/')
63
  def index():
64
+ """مسار عرض الواجهة الأمامية."""
65
  return render_template('index.html')
66
 
 
67
  @app.route('/check', methods=['POST'])
68
  def check():
69
+ """مسار فحص كلمة المرور واسترجاع النتائج."""
70
  data = request.get_json()
71
  password = data.get('password', '')
72
 
73
  status, color, feedback = check_password_strength(password)
74
 
 
75
  return jsonify({
76
  'status': status,
77
  'color': color,
78
  'feedback': feedback
79
  })
80
 
81
+ # ----------------------------------------------------------------------
82
+ # 3. تشغيل التطبيق (مع التعديل الضروري)
83
+ # ----------------------------------------------------------------------
84
+
85
  if __name__ == '__main__':
86
+ # **التعديل الهام:** تحديد المضيف (host) على '0.0.0.0'
87
+ # هذا يحل مشكلة 'رفض الاتصال' عند العمل على خوادم الاستضافة الخارجية.
88
+ app.run(host='0.0.0.0', debug=True)