Spaces:
Sleeping
Sleeping
File size: 1,113 Bytes
da55044 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
import random
import string
def generate_password(length=12):
if length < 4:
return "Password length should be at least 4 to include all character types."
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
special_chars = string.punctuation
password = [
random.choice(lowercase),
random.choice(uppercase),
random.choice(digits),
random.choice(special_chars),
]
all_chars = lowercase + uppercase + digits + special_chars
password += random.choices(all_chars, k=length - 4)
random.shuffle(password)
return ''.join(password)
st.title("Password Generator 🔑")
st.sidebar.header("Password Settings")
length = st.sidebar.slider("Password Length", min_value=4, max_value=50, value=12)
generate_btn = st.sidebar.button("Generate Password")
if generate_btn:
password = generate_password(length)
st.subheader("Generated Password")
st.code(password)
else:
st.write("Adjust the length and click 'Generate Password' to create a secure password.") |