muhammadrazapathan commited on
Commit
4d341bd
Β·
verified Β·
1 Parent(s): 97613e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Length check
15
+ if len(password) >= 8:
16
+ score += 1
17
+ else:
18
+ feedback.append("❌ Password should be at least 8 characters long.")
19
+
20
+ if len(password) >= 12:
21
+ score += 1
22
+
23
+ # Uppercase check
24
+ if re.search(r"[A-Z]", password):
25
+ score += 1
26
+ else:
27
+ feedback.append("❌ Add at least one uppercase letter (A-Z).")
28
+
29
+ # Lowercase check
30
+ if re.search(r"[a-z]", password):
31
+ score += 1
32
+ else:
33
+ feedback.append("❌ Add at least one lowercase letter (a-z).")
34
+
35
+ # Number check
36
+ if re.search(r"[0-9]", password):
37
+ score += 1
38
+ else:
39
+ feedback.append("❌ Add at least one number (0-9).")
40
+
41
+ # Special character check
42
+ if re.search(r"[!@#$%^&*(),.?\":{}|<>]", password):
43
+ score += 1
44
+ else:
45
+ feedback.append("❌ Add at least one special character (!@#$%^&* etc.).")
46
+
47
+ # Common password check
48
+ if password.lower() in COMMON_PASSWORDS:
49
+ feedback.append("❌ This password is very common and easy to guess.")
50
+ else:
51
+ score += 1
52
+
53
+ # Strength levels
54
+ if score <= 2:
55
+ strength = "Very Weak ❌"
56
+ elif score <= 4:
57
+ strength = "Weak ⚠️"
58
+ elif score <= 6:
59
+ strength = "Medium πŸ™‚"
60
+ elif score <= 7:
61
+ strength = "Strong πŸ’ͺ"
62
+ else:
63
+ strength = "Very Strong πŸ”₯"
64
+
65
+ if not feedback:
66
+ feedback.append("βœ… Great! Your password is strong.")
67
+
68
+ return strength, score, "\n".join(feedback)
69
+
70
+ # ---------- Modern UI ----------
71
+ with gr.Blocks(title="πŸ” Password Security Analyzer") as app:
72
+ gr.Markdown(
73
+ """
74
+ # πŸ” Password Security Analyzer
75
+ Check how strong your password is and get smart tips to improve security.
76
+ """
77
+ )
78
+
79
+ with gr.Row():
80
+ password_input = gr.Textbox(
81
+ label="Enter Your Password",
82
+ type="password",
83
+ placeholder="Type your password here...",
84
+ scale=2
85
+ )
86
+
87
+ analyze_btn = gr.Button("Analyze Password πŸš€", variant="primary")
88
+
89
+ with gr.Row():
90
+ strength_output = gr.Textbox(label="Strength Level")
91
+ score_output = gr.Number(label="Security Score (0–8)")
92
+
93
+ feedback_output = gr.Textbox(
94
+ label="Security Tips & Feedback",
95
+ lines=4
96
+ )
97
+
98
+ analyze_btn.click(
99
+ fn=analyze_password,
100
+ inputs=password_input,
101
+ outputs=[strength_output, score_output, feedback_output]
102
+ )
103
+
104
+ if __name__ == "__main__":
105
+ app.launch()