Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,15 @@
|
|
| 2 |
|
| 3 |
from flask import Flask, render_template, request, jsonify
|
| 4 |
import re
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
|
| 9 |
# ----------------------------------------------------------------------
|
| 10 |
-
# تحميل قائمة كلمات المرور المسربة
|
| 11 |
# ----------------------------------------------------------------------
|
| 12 |
|
| 13 |
-
# استخدام مجموعة (Set) لسرعة البحث العالية جداً
|
| 14 |
LEAKED_PASSWORDS = set()
|
| 15 |
|
| 16 |
def load_leaked_passwords(file_path='leaked_passwords.txt'):
|
|
@@ -19,7 +19,8 @@ def load_leaked_passwords(file_path='leaked_passwords.txt'):
|
|
| 19 |
# ⚠️ إذا لم يتم العثور على الملف، نستخدم قائمة صغيرة للاختبار
|
| 20 |
if not os.path.exists(file_path):
|
| 21 |
print(f"⚠️ الملف {file_path} غير موجود. سيتم استخدام قائمة صغيرة للاختبار.")
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
try:
|
| 25 |
# قراءة الملف وإضافة الكلمات بعد تحويلها لأحرف صغيرة
|
|
@@ -29,6 +30,8 @@ def load_leaked_passwords(file_path='leaked_passwords.txt'):
|
|
| 29 |
print(f"✅ تم تحميل {len(LEAKED_PASSWORDS)} كلمة مرور مسربة بنجاح.")
|
| 30 |
except Exception as e:
|
| 31 |
print(f"❌ حدث خطأ أثناء تحميل الملف: {e}")
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# تنفيذ دالة التحميل عند بدء التطبيق
|
| 34 |
# سيتم تخزين جميع الكلمات في متغير LEAKED_PASSWORDS
|
|
@@ -43,9 +46,7 @@ def check_password_strength(password):
|
|
| 43 |
"""تحليل قوة كلمة المرور وحساب النسبة المئوية."""
|
| 44 |
score = 0
|
| 45 |
feedback = []
|
| 46 |
-
|
| 47 |
-
# ⚠️ أقصى نقاط يمكن تحقيقها هي 6
|
| 48 |
-
MAX_SCORE = 6
|
| 49 |
|
| 50 |
# أ. قواعد قوة كلمة المرور
|
| 51 |
if len(password) >= 12:
|
|
@@ -61,10 +62,9 @@ def check_password_strength(password):
|
|
| 61 |
if re.search(r"[a-z]", password): score += 1
|
| 62 |
if re.search(r"[A-Z]", password): score += 1
|
| 63 |
if re.search(r"\d", password): score += 1
|
| 64 |
-
if re.search(r"[^a-zA-Z0-9\s]", password): score += 1
|
| 65 |
|
| 66 |
-
# ب. التحقق من التسريب
|
| 67 |
-
# ملاحظة: يتم التحقق من القائمة الصغيرة إذا لم يكن الملف النصي موجوداً
|
| 68 |
is_leaked = password.lower() in LEAKED_PASSWORDS
|
| 69 |
|
| 70 |
# ------------------
|
|
@@ -91,31 +91,30 @@ def check_password_strength(password):
|
|
| 91 |
status = "ضعيفة"
|
| 92 |
color = "red"
|
| 93 |
|
| 94 |
-
# نُرجع النسبة المئوية أيضاً الآن
|
| 95 |
return status, color, feedback, percentage
|
| 96 |
|
| 97 |
# ----------------------------------------------------------------------
|
| 98 |
# 2. مسارات تطبيق Flask
|
| 99 |
# ----------------------------------------------------------------------
|
| 100 |
|
|
|
|
| 101 |
@app.route('/')
|
| 102 |
def index():
|
| 103 |
-
|
|
|
|
| 104 |
|
| 105 |
@app.route('/check', methods=['POST'])
|
| 106 |
def check():
|
| 107 |
data = request.get_json()
|
| 108 |
password = data.get('password', '')
|
| 109 |
|
| 110 |
-
# استقبال النسبة المئوية
|
| 111 |
status, color, feedback, percentage = check_password_strength(password)
|
| 112 |
|
| 113 |
-
# إرجاع النتيجة
|
| 114 |
return jsonify({
|
| 115 |
'status': status,
|
| 116 |
'color': color,
|
| 117 |
'feedback': feedback,
|
| 118 |
-
'percentage': percentage
|
| 119 |
})
|
| 120 |
|
| 121 |
# ----------------------------------------------------------------------
|
|
@@ -123,5 +122,4 @@ def check():
|
|
| 123 |
# ----------------------------------------------------------------------
|
| 124 |
|
| 125 |
if __name__ == '__main__':
|
| 126 |
-
# التشغيل على host='0.0.0.0' و port=7860
|
| 127 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
| 2 |
|
| 3 |
from flask import Flask, render_template, request, jsonify
|
| 4 |
import re
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
|
| 9 |
# ----------------------------------------------------------------------
|
| 10 |
+
# تحميل قائمة كلمات المرور المسربة (من ملف leaked_passwords.txt)
|
| 11 |
# ----------------------------------------------------------------------
|
| 12 |
|
| 13 |
+
# استخدام مجموعة (Set) لسرعة البحث العالية جداً في قائمة ضخمة
|
| 14 |
LEAKED_PASSWORDS = set()
|
| 15 |
|
| 16 |
def load_leaked_passwords(file_path='leaked_passwords.txt'):
|
|
|
|
| 19 |
# ⚠️ إذا لم يتم العثور على الملف، نستخدم قائمة صغيرة للاختبار
|
| 20 |
if not os.path.exists(file_path):
|
| 21 |
print(f"⚠️ الملف {file_path} غير موجود. سيتم استخدام قائمة صغيرة للاختبار.")
|
| 22 |
+
# هذه القائمة تحاكي الكلمات الأكثر شيوعاً
|
| 23 |
+
return {"123456", "password", "كلمةسر", "محمد", "qwerty", "admin", "تيكتوك", "مرحبا123"}
|
| 24 |
|
| 25 |
try:
|
| 26 |
# قراءة الملف وإضافة الكلمات بعد تحويلها لأحرف صغيرة
|
|
|
|
| 30 |
print(f"✅ تم تحميل {len(LEAKED_PASSWORDS)} كلمة مرور مسربة بنجاح.")
|
| 31 |
except Exception as e:
|
| 32 |
print(f"❌ حدث خطأ أثناء تحميل الملف: {e}")
|
| 33 |
+
# في حالة فشل القراءة، نرجع قائمة صغيرة لعدم توقيف التطبيق
|
| 34 |
+
return {"123456", "password"}
|
| 35 |
|
| 36 |
# تنفيذ دالة التحميل عند بدء التطبيق
|
| 37 |
# سيتم تخزين جميع الكلمات في متغير LEAKED_PASSWORDS
|
|
|
|
| 46 |
"""تحليل قوة كلمة المرور وحساب النسبة المئوية."""
|
| 47 |
score = 0
|
| 48 |
feedback = []
|
| 49 |
+
MAX_SCORE = 6 # (طول + صغير + كبير + رقم + رمز/عربي + نقطة إضافية للطول الجيد)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# أ. قواعد قوة كلمة المرور
|
| 52 |
if len(password) >= 12:
|
|
|
|
| 62 |
if re.search(r"[a-z]", password): score += 1
|
| 63 |
if re.search(r"[A-Z]", password): score += 1
|
| 64 |
if re.search(r"\d", password): score += 1
|
| 65 |
+
if re.search(r"[^a-zA-Z0-9\s]", password): score += 1
|
| 66 |
|
| 67 |
+
# ب. التحقق من التسريب
|
|
|
|
| 68 |
is_leaked = password.lower() in LEAKED_PASSWORDS
|
| 69 |
|
| 70 |
# ------------------
|
|
|
|
| 91 |
status = "ضعيفة"
|
| 92 |
color = "red"
|
| 93 |
|
|
|
|
| 94 |
return status, color, feedback, percentage
|
| 95 |
|
| 96 |
# ----------------------------------------------------------------------
|
| 97 |
# 2. مسارات تطبيق Flask
|
| 98 |
# ----------------------------------------------------------------------
|
| 99 |
|
| 100 |
+
# ⚠️ تم تعديل هذا المسار لاستخدام ملف HTML الجديد
|
| 101 |
@app.route('/')
|
| 102 |
def index():
|
| 103 |
+
# عند الوصول للرابط الرئيسي، يتم عرض أداة فحص كلمة المرور مباشرة
|
| 104 |
+
return render_template('password-strength.html')
|
| 105 |
|
| 106 |
@app.route('/check', methods=['POST'])
|
| 107 |
def check():
|
| 108 |
data = request.get_json()
|
| 109 |
password = data.get('password', '')
|
| 110 |
|
|
|
|
| 111 |
status, color, feedback, percentage = check_password_strength(password)
|
| 112 |
|
|
|
|
| 113 |
return jsonify({
|
| 114 |
'status': status,
|
| 115 |
'color': color,
|
| 116 |
'feedback': feedback,
|
| 117 |
+
'percentage': percentage
|
| 118 |
})
|
| 119 |
|
| 120 |
# ----------------------------------------------------------------------
|
|
|
|
| 122 |
# ----------------------------------------------------------------------
|
| 123 |
|
| 124 |
if __name__ == '__main__':
|
|
|
|
| 125 |
app.run(host='0.0.0.0', port=7860, debug=True)
|