Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
|
@@ -4,20 +4,30 @@ import bcrypt
|
|
| 4 |
def hash_password(password: str) -> str:
|
| 5 |
if not password:
|
| 6 |
return "β Please enter a password"
|
| 7 |
-
# Convert to bytes
|
| 8 |
pw_bytes = password.encode("utf-8")
|
| 9 |
-
# Generate salt + hash
|
| 10 |
hashed = bcrypt.hashpw(pw_bytes, bcrypt.gensalt(rounds=12))
|
| 11 |
return hashed.decode("utf-8")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
demo.launch()
|
|
|
|
| 4 |
def hash_password(password: str) -> str:
|
| 5 |
if not password:
|
| 6 |
return "β Please enter a password"
|
|
|
|
| 7 |
pw_bytes = password.encode("utf-8")
|
|
|
|
| 8 |
hashed = bcrypt.hashpw(pw_bytes, bcrypt.gensalt(rounds=12))
|
| 9 |
return hashed.decode("utf-8")
|
| 10 |
|
| 11 |
+
def toggle_password(show_password: bool):
|
| 12 |
+
return gr.update(type="text" if show_password else "password")
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("## π Password Hasher (bcrypt)\nEnter a password to generate its bcrypt hash")
|
| 16 |
+
|
| 17 |
+
with gr.Row():
|
| 18 |
+
password_input = gr.Textbox(
|
| 19 |
+
type="password", label="Enter your password", placeholder="Type password here..."
|
| 20 |
+
)
|
| 21 |
+
show_checkbox = gr.Checkbox(label="Show password", value=False)
|
| 22 |
+
|
| 23 |
+
hash_output = gr.Textbox(label="Generated hash")
|
| 24 |
+
|
| 25 |
+
# Button to generate hash
|
| 26 |
+
hash_btn = gr.Button("Generate Hash")
|
| 27 |
+
hash_btn.click(fn=hash_password, inputs=password_input, outputs=hash_output)
|
| 28 |
+
|
| 29 |
+
# Toggle password visibility
|
| 30 |
+
show_checkbox.change(fn=toggle_password, inputs=show_checkbox, outputs=password_input)
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch()
|