File size: 757 Bytes
9ac430b
 
22b6e1b
9ac430b
22b6e1b
 
 
 
9ac430b
22b6e1b
9c1b601
 
22b6e1b
9c1b601
22b6e1b
9c1b601
22b6e1b
 
9ac430b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()