Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
# Common weak passwords list
|
| 5 |
+
COMMON_PASSWORDS = [
|
| 6 |
+
"password", "123456", "123456789", "qwerty", "abc123",
|
| 7 |
+
"password123", "admin", "letmein", "welcome", "iloveyou"
|
| 8 |
+
]
|
| 9 |
+
|
| 10 |
+
def analyze_password(password):
|
| 11 |
+
score = 0
|
| 12 |
+
feedback = []
|
| 13 |
+
|
| 14 |
+
if len(password) >= 8:
|
| 15 |
+
score += 1
|
| 16 |
+
else:
|
| 17 |
+
feedback.append("β Password should be at least 8 characters long.")
|
| 18 |
+
|
| 19 |
+
if len(password) >= 12:
|
| 20 |
+
score += 1
|
| 21 |
+
|
| 22 |
+
if re.search(r"[A-Z]", password):
|
| 23 |
+
score += 1
|
| 24 |
+
else:
|
| 25 |
+
feedback.append("β Add at least one uppercase letter (A-Z).")
|
| 26 |
+
|
| 27 |
+
if re.search(r"[a-z]", password):
|
| 28 |
+
score += 1
|
| 29 |
+
else:
|
| 30 |
+
feedback.append("β Add at least one lowercase letter (a-z).")
|
| 31 |
+
|
| 32 |
+
if re.search(r"[0-9]", password):
|
| 33 |
+
score += 1
|
| 34 |
+
else:
|
| 35 |
+
feedback.append("β Add at least one number (0-9).")
|
| 36 |
+
|
| 37 |
+
if re.search(r"[!@#$%^&*(),.?\":{}|<>]", password):
|
| 38 |
+
score += 1
|
| 39 |
+
else:
|
| 40 |
+
feedback.append("β Add at least one special character (!@#$%^&* etc.).")
|
| 41 |
+
|
| 42 |
+
if password.lower() in COMMON_PASSWORDS:
|
| 43 |
+
feedback.append("β This password is very common and easy to guess.")
|
| 44 |
+
else:
|
| 45 |
+
score += 1
|
| 46 |
+
|
| 47 |
+
if score <= 2:
|
| 48 |
+
strength = "Very Weak β"
|
| 49 |
+
elif score <= 4:
|
| 50 |
+
strength = "Weak β οΈ"
|
| 51 |
+
elif score <= 6:
|
| 52 |
+
strength = "Medium π"
|
| 53 |
+
elif score <= 7:
|
| 54 |
+
strength = "Strong πͺ"
|
| 55 |
+
else:
|
| 56 |
+
strength = "Very Strong π₯"
|
| 57 |
+
|
| 58 |
+
if not feedback:
|
| 59 |
+
feedback.append("β
Excellent! Your password is very secure.")
|
| 60 |
+
|
| 61 |
+
return strength, score, "\n".join(feedback), score
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# ---------- Modern UI ----------
|
| 65 |
+
with gr.Blocks(title="π Password Security Analyzer", theme=gr.themes.Soft()) as app:
|
| 66 |
+
gr.Markdown(
|
| 67 |
+
"""
|
| 68 |
+
<h1 style="text-align:center;">π Password Security Analyzer</h1>
|
| 69 |
+
<p style="text-align:center;">Test your password strength and improve your security instantly.</p>
|
| 70 |
+
""",
|
| 71 |
+
elem_id="header"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column(scale=2):
|
| 76 |
+
password_input = gr.Textbox(
|
| 77 |
+
label="Enter Your Password",
|
| 78 |
+
type="password",
|
| 79 |
+
placeholder="Type your password here..."
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
show_password = gr.Checkbox(label="π Show Password")
|
| 83 |
+
|
| 84 |
+
analyze_btn = gr.Button("Analyze Password π", variant="primary")
|
| 85 |
+
|
| 86 |
+
with gr.Column(scale=1):
|
| 87 |
+
gr.Markdown("### π Results")
|
| 88 |
+
strength_output = gr.Textbox(label="Strength Level")
|
| 89 |
+
score_output = gr.Number(label="Security Score (0β8)")
|
| 90 |
+
|
| 91 |
+
strength_bar = gr.Slider(
|
| 92 |
+
minimum=0,
|
| 93 |
+
maximum=8,
|
| 94 |
+
step=1,
|
| 95 |
+
label="Strength Meter",
|
| 96 |
+
interactive=False
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
feedback_output = gr.Textbox(
|
| 100 |
+
label="π‘ Security Tips & Feedback",
|
| 101 |
+
lines=5
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# Toggle password visibility
|
| 105 |
+
def toggle_visibility(show):
|
| 106 |
+
return gr.update(type="text" if show else "password")
|
| 107 |
+
|
| 108 |
+
show_password.change(
|
| 109 |
+
fn=toggle_visibility,
|
| 110 |
+
inputs=show_password,
|
| 111 |
+
outputs=password_input
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
analyze_btn.click(
|
| 115 |
+
fn=analyze_password,
|
| 116 |
+
inputs=password_input,
|
| 117 |
+
outputs=[strength_output, score_output, feedback_output, strength_bar]
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
app.launch()
|