Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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 |
-
|
| 67 |
-
return gr.update(type=new_type),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 95 |
-
|
|
|
|
| 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 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
| 103 |
-
demo.launch(
|
|
|
|
| 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()
|