Skydata001 commited on
Commit
019eb9c
·
verified ·
1 Parent(s): c872fd0

Update app.py

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