Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import bcrypt | |
| import secrets | |
| def generate_hash() -> str: | |
| # generate a random password/token each time | |
| random_password = secrets.token_hex(8) # 16-char random string | |
| pw_bytes = random_password.encode("utf-8") | |
| hashed = bcrypt.hashpw(pw_bytes, bcrypt.gensalt(rounds=12)) | |
| return f"π Random password: {random_password}\n\nπ Hash: {hashed.decode('utf-8')}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π Random Password Hasher (bcrypt)\nClick the button to generate a random password and its hash") | |
| output_box = gr.Textbox(label="Result", lines=4) | |
| gen_btn = gr.Button("Generate Hash") | |
| gen_btn.click(fn=generate_hash, inputs=None, outputs=output_box) | |
| if __name__ == "__main__": | |
| demo.launch() | |