File size: 3,360 Bytes
3e57780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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()