muhammadrazapathan commited on
Commit
3e57780
Β·
verified Β·
1 Parent(s): 4bbad08

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -0
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()