hassan773 commited on
Commit
f5b626e
Β·
verified Β·
1 Parent(s): c7ed8c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -19
app.py CHANGED
@@ -7,19 +7,15 @@ def estimate_crack_time(password):
7
  if not password:
8
  return "0 seconds"
9
 
10
- # Calculate character set size (L)
11
  L = 0
12
  if re.search(r"[a-z]", password): L += 26
13
  if re.search(r"[A-Z]", password): L += 26
14
  if re.search(r"\d", password): L += 10
15
  if re.search(r"[!@#$%^&*(),.?\":{}|<>]", password): L += 32
16
 
17
- if L == 0: L = 1 # Avoid log errors
18
 
19
- # Combinations = L ^ length
20
  combinations = math.pow(L, len(password))
21
-
22
- # Assuming 10 billion guesses per second (standard high-end brute force)
23
  seconds = combinations / 10_000_000_000
24
 
25
  if seconds < 1: return "Instantly ⚑"
@@ -37,7 +33,6 @@ def analyze_password(password):
37
 
38
  checklist_html, strength = render_checklist(password)
39
  crack_time = estimate_crack_time(password)
40
-
41
  return checklist_html, strength, crack_time
42
 
43
  def render_checklist(password):
@@ -63,26 +58,51 @@ def render_checklist(password):
63
 
64
  def toggle_visibility(is_visible):
65
  new_type = "text" if is_visible else "password"
66
- new_label = "Hide Password πŸ‘οΈ" if is_visible else "Show Password πŸ‘οΈβ€πŸ—¨οΈ"
67
- return gr.update(type=new_type), new_label, not is_visible
 
 
 
 
 
 
 
 
68
 
 
69
  toggle_dark_js = """() => { document.body.classList.toggle('dark'); }"""
70
 
71
- # 3. UI Build
72
  custom_css = """
73
  .gradio-container { max-width: 800px; margin: auto; }
74
- .avg-btn { max-width: 250px !important; margin: auto !important; width: 100%; }
 
 
 
 
 
 
 
75
  .time-display { font-size: 1.5em; font-weight: bold; color: #ff4b4b; }
76
  """
77
 
78
- with gr.Blocks() as demo:
79
  gr.Markdown("# πŸ›‘οΈ SecurePass Pro Analyzer")
 
 
80
  visible_state = gr.State(True)
 
81
 
82
  with gr.Row():
83
- with gr.Column(scale=3):
84
- pass_input = gr.Textbox(label="Enter Password", type="password", buttons=["copy"])
85
- show_btn = gr.Button("Show Password πŸ‘οΈβ€πŸ—¨οΈ", variant="secondary", elem_classes="avg-btn")
 
 
 
 
 
 
 
86
  with gr.Column(scale=2):
87
  strength_meter = gr.Slider(label="Strength (%)", interactive=False)
88
  gr.Markdown("### πŸ•’ Estimated Crack Time:")
@@ -91,13 +111,27 @@ with gr.Blocks() as demo:
91
  checklist_area = gr.HTML(value=render_checklist("")[0])
92
 
93
  with gr.Row():
94
- dark_btn = gr.Button("πŸŒ™ Dark Mode", variant="secondary", elem_classes="avg-btn")
95
- reset_btn = gr.Button("πŸ—‘οΈ Clear", variant="stop", elem_classes="avg-btn")
 
96
 
 
97
  pass_input.change(analyze_password, pass_input, [checklist_area, strength_meter, time_output])
98
  show_btn.click(toggle_visibility, [visible_state], [pass_input, show_btn, visible_state])
99
- dark_btn.click(None, None, None, js=toggle_dark_js)
100
- reset_btn.click(lambda: ["", render_checklist("")[0], 0, "0 seconds"], None, [pass_input, checklist_area, strength_meter, time_output])
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  if __name__ == "__main__":
103
- demo.launch(theme=gr.themes.Soft(), css=custom_css)
 
7
  if not password:
8
  return "0 seconds"
9
 
 
10
  L = 0
11
  if re.search(r"[a-z]", password): L += 26
12
  if re.search(r"[A-Z]", password): L += 26
13
  if re.search(r"\d", password): L += 10
14
  if re.search(r"[!@#$%^&*(),.?\":{}|<>]", password): L += 32
15
 
16
+ if L == 0: L = 1
17
 
 
18
  combinations = math.pow(L, len(password))
 
 
19
  seconds = combinations / 10_000_000_000
20
 
21
  if seconds < 1: return "Instantly ⚑"
 
33
 
34
  checklist_html, strength = render_checklist(password)
35
  crack_time = estimate_crack_time(password)
 
36
  return checklist_html, strength, crack_time
37
 
38
  def render_checklist(password):
 
58
 
59
  def toggle_visibility(is_visible):
60
  new_type = "text" if is_visible else "password"
61
+ new_icon = "πŸ™ˆ" if is_visible else "πŸ‘οΈ"
62
+ return gr.update(type=new_type), new_icon, not is_visible
63
+
64
+ # --- NEW DARK MODE TOGGLE LOGIC ---
65
+ def toggle_dark_mode(current_is_dark):
66
+ # Toggle the boolean state
67
+ new_state = not current_is_dark
68
+ # Update button label based on the new state
69
+ new_label = "β˜€οΈ Light Mode" if new_state else "πŸŒ™ Dark Mode"
70
+ return new_label, new_state
71
 
72
+ # JS to handle the actual CSS class toggle
73
  toggle_dark_js = """() => { document.body.classList.toggle('dark'); }"""
74
 
 
75
  custom_css = """
76
  .gradio-container { max-width: 800px; margin: auto; }
77
+ .eye-btn {
78
+ max-width: 50px !important;
79
+ min-width: 50px !important;
80
+ height: 45px !important;
81
+ align-self: end;
82
+ margin-bottom: 10px;
83
+ font-size: 1.2em !important;
84
+ }
85
  .time-display { font-size: 1.5em; font-weight: bold; color: #ff4b4b; }
86
  """
87
 
88
+ with gr.Blocks(css=custom_css) as demo:
89
  gr.Markdown("# πŸ›‘οΈ SecurePass Pro Analyzer")
90
+
91
+ # State variables
92
  visible_state = gr.State(True)
93
+ dark_state = gr.State(False) # Tracks if dark mode is ON or OFF
94
 
95
  with gr.Row():
96
+ with gr.Column(scale=4):
97
+ with gr.Row():
98
+ pass_input = gr.Textbox(
99
+ label="Enter Password",
100
+ type="password",
101
+ show_copy_button=True,
102
+ scale=9
103
+ )
104
+ show_btn = gr.Button("πŸ‘οΈ", elem_classes="eye-btn", scale=1)
105
+
106
  with gr.Column(scale=2):
107
  strength_meter = gr.Slider(label="Strength (%)", interactive=False)
108
  gr.Markdown("### πŸ•’ Estimated Crack Time:")
 
111
  checklist_area = gr.HTML(value=render_checklist("")[0])
112
 
113
  with gr.Row():
114
+ # The button now starts as "Dark Mode"
115
+ dark_btn = gr.Button("πŸŒ™ Dark Mode", variant="secondary")
116
+ reset_btn = gr.Button("πŸ—‘οΈ Clear", variant="stop")
117
 
118
+ # Event Handlers
119
  pass_input.change(analyze_password, pass_input, [checklist_area, strength_meter, time_output])
120
  show_btn.click(toggle_visibility, [visible_state], [pass_input, show_btn, visible_state])
121
+
122
+ # Dark Mode Handler: Update UI text AND trigger JS
123
+ dark_btn.click(
124
+ toggle_dark_mode,
125
+ inputs=[dark_state],
126
+ outputs=[dark_btn, dark_state],
127
+ js=toggle_dark_js
128
+ )
129
+
130
+ reset_btn.click(
131
+ lambda: ["", render_checklist("")[0], 0, "0 seconds"],
132
+ None,
133
+ [pass_input, checklist_area, strength_meter, time_output]
134
+ )
135
 
136
  if __name__ == "__main__":
137
+ demo.launch()