Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import bcrypt
|
|
|
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
pw_bytes =
|
| 8 |
hashed = bcrypt.hashpw(pw_bytes, bcrypt.gensalt(rounds=12))
|
| 9 |
-
return hashed.decode(
|
| 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)\
|
| 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 |
-
|
| 26 |
-
hash_btn = gr.Button("Generate Hash")
|
| 27 |
-
hash_btn.click(fn=hash_password, inputs=password_input, outputs=hash_output)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import bcrypt
|
| 3 |
+
import secrets
|
| 4 |
|
| 5 |
+
def generate_hash() -> str:
|
| 6 |
+
# generate a random password/token each time
|
| 7 |
+
random_password = secrets.token_hex(8) # 16-char random string
|
| 8 |
+
pw_bytes = random_password.encode("utf-8")
|
| 9 |
hashed = bcrypt.hashpw(pw_bytes, bcrypt.gensalt(rounds=12))
|
| 10 |
+
return f"π Random password: {random_password}\n\nπ Hash: {hashed.decode('utf-8')}"
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
+
gr.Markdown("## π Random Password Hasher (bcrypt)\nClick the button to generate a random password and its hash")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
output_box = gr.Textbox(label="Result", lines=4)
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
gen_btn = gr.Button("Generate Hash")
|
| 18 |
+
gen_btn.click(fn=generate_hash, inputs=None, outputs=output_box)
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
demo.launch()
|