import gradio as gr import re # Common weak passwords list COMMON_PASSWORDS = [ "password", "123456", "123456789", "qwerty", "abc123", "password123", "admin", "letmein", "welcome", "iloveyou" ] def analyze_password(password): score = 0 feedback = [] if len(password) >= 8: score += 1 else: feedback.append("❌ Password should be at least 8 characters long.") if len(password) >= 12: score += 1 if re.search(r"[A-Z]", password): score += 1 else: feedback.append("❌ Add at least one uppercase letter (A-Z).") if re.search(r"[a-z]", password): score += 1 else: feedback.append("❌ Add at least one lowercase letter (a-z).") if re.search(r"[0-9]", password): score += 1 else: feedback.append("❌ Add at least one number (0-9).") if re.search(r"[!@#$%^&*(),.?\":{}|<>]", password): score += 1 else: feedback.append("❌ Add at least one special character (!@#$%^&* etc.).") if password.lower() in COMMON_PASSWORDS: feedback.append("❌ This password is very common and easy to guess.") else: score += 1 if score <= 2: strength = "Very Weak ❌" elif score <= 4: strength = "Weak ⚠️" elif score <= 6: strength = "Medium 🙂" elif score <= 7: strength = "Strong 💪" else: strength = "Very Strong 🔥" if not feedback: feedback.append("✅ Excellent! Your password is very secure.") return strength, score, "\n".join(feedback), score # ---------- Modern UI ---------- with gr.Blocks(title="🔐 Password Security Analyzer", theme=gr.themes.Soft()) as app: gr.Markdown( """

🔐 Password Security Analyzer

Test your password strength and improve your security instantly.

""", elem_id="header" ) with gr.Row(): with gr.Column(scale=2): password_input = gr.Textbox( label="Enter Your Password", type="password", placeholder="Type your password here..." ) show_password = gr.Checkbox(label="👁 Show Password") analyze_btn = gr.Button("Analyze Password 🚀", variant="primary") with gr.Column(scale=1): gr.Markdown("### 🔎 Results") strength_output = gr.Textbox(label="Strength Level") score_output = gr.Number(label="Security Score (0–8)") strength_bar = gr.Slider( minimum=0, maximum=8, step=1, label="Strength Meter", interactive=False ) feedback_output = gr.Textbox( label="🛡 Security Tips & Feedback", lines=5 ) # Toggle password visibility def toggle_visibility(show): return gr.update(type="text" if show else "password") show_password.change( fn=toggle_visibility, inputs=show_password, outputs=password_input ) analyze_btn.click( fn=analyze_password, inputs=password_input, outputs=[strength_output, score_output, feedback_output, strength_bar] ) if __name__ == "__main__": app.launch()