Download app.py from muhammadrazapathan/Secure_pro_analyzer: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/spaces/muhammadrazapathan/Secure_pro_analyzer/resolve/main/app.py
- Command line
-
hf download hf://spaces/muhammadrazapathan/Secure_pro_analyzer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/muhammadrazapathan/Secure_pro_analyzer/resolve/main/app.py
3.36 kB
| 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( | |
| """ | |
| <h1 style="text-align:center;">π Password Security Analyzer</h1> | |
| <p style="text-align:center;">Test your password strength and improve your security instantly.</p> | |
| """, | |
| 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() | |