Mohammed98 commited on
Commit
9c1b601
Β·
verified Β·
1 Parent(s): c500626

update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
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
- # Gradio Interface
14
- demo = gr.Interface(
15
- fn=hash_password,
16
- inputs=gr.Textbox(type="password", label="Enter your password"),
17
- outputs=gr.Textbox(label="Generated hash"),
18
- title="Password Hasher πŸ”",
19
- description="Enter a password and get its bcrypt hash"
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()