Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,19 @@ import streamlit as st
|
|
| 2 |
import random
|
| 3 |
import string
|
| 4 |
|
| 5 |
-
# Session state
|
|
|
|
|
|
|
|
|
|
| 6 |
if "saved_passwords" not in st.session_state:
|
| 7 |
st.session_state.saved_passwords = []
|
| 8 |
|
|
|
|
| 9 |
# Dark mode toggle
|
| 10 |
dark_mode = st.toggle("π Dark Mode")
|
| 11 |
|
| 12 |
-
if dark_mode:
|
| 13 |
-
st.markdown(
|
| 14 |
-
"""
|
| 15 |
-
<style>
|
| 16 |
-
body {
|
| 17 |
-
background-color: #0E1117;
|
| 18 |
-
color: white;
|
| 19 |
-
}
|
| 20 |
-
</style>
|
| 21 |
-
""",
|
| 22 |
-
unsafe_allow_html=True
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
st.title("π Advanced Password Generator App")
|
| 26 |
|
| 27 |
-
st.write("Generate strong passwords and manage them easily!")
|
| 28 |
-
|
| 29 |
# Password length
|
| 30 |
length = st.slider("Select Password Length", 4, 32, 12)
|
| 31 |
|
|
@@ -50,7 +39,7 @@ if symbols:
|
|
| 50 |
characters += string.punctuation
|
| 51 |
|
| 52 |
|
| 53 |
-
# Password strength checker
|
| 54 |
def check_strength(password):
|
| 55 |
|
| 56 |
strength = 0
|
|
@@ -75,29 +64,32 @@ def check_strength(password):
|
|
| 75 |
return "Strong β
"
|
| 76 |
|
| 77 |
|
| 78 |
-
# Generate password
|
| 79 |
if st.button("Generate Password"):
|
| 80 |
|
| 81 |
if characters == "":
|
| 82 |
st.warning("Please select at least one option!")
|
| 83 |
|
| 84 |
else:
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
st.write("Password Strength:", strength)
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
st.session_state.
|
| 100 |
-
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
# Show saved passwords
|
|
|
|
| 2 |
import random
|
| 3 |
import string
|
| 4 |
|
| 5 |
+
# Session state setup
|
| 6 |
+
if "generated_password" not in st.session_state:
|
| 7 |
+
st.session_state.generated_password = ""
|
| 8 |
+
|
| 9 |
if "saved_passwords" not in st.session_state:
|
| 10 |
st.session_state.saved_passwords = []
|
| 11 |
|
| 12 |
+
|
| 13 |
# Dark mode toggle
|
| 14 |
dark_mode = st.toggle("π Dark Mode")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
st.title("π Advanced Password Generator App")
|
| 17 |
|
|
|
|
|
|
|
| 18 |
# Password length
|
| 19 |
length = st.slider("Select Password Length", 4, 32, 12)
|
| 20 |
|
|
|
|
| 39 |
characters += string.punctuation
|
| 40 |
|
| 41 |
|
| 42 |
+
# Password strength checker
|
| 43 |
def check_strength(password):
|
| 44 |
|
| 45 |
strength = 0
|
|
|
|
| 64 |
return "Strong β
"
|
| 65 |
|
| 66 |
|
| 67 |
+
# Generate password button
|
| 68 |
if st.button("Generate Password"):
|
| 69 |
|
| 70 |
if characters == "":
|
| 71 |
st.warning("Please select at least one option!")
|
| 72 |
|
| 73 |
else:
|
| 74 |
+
st.session_state.generated_password = ''.join(
|
| 75 |
+
random.choice(characters) for _ in range(length)
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
|
| 79 |
+
# Show password (permanent display)
|
| 80 |
+
if st.session_state.generated_password:
|
| 81 |
|
| 82 |
+
st.success("Generated Password:")
|
| 83 |
+
st.code(st.session_state.generated_password)
|
|
|
|
| 84 |
|
| 85 |
+
strength = check_strength(st.session_state.generated_password)
|
| 86 |
+
st.write("Password Strength:", strength)
|
| 87 |
|
| 88 |
+
if st.button("Save Password"):
|
| 89 |
+
st.session_state.saved_passwords.append(
|
| 90 |
+
st.session_state.generated_password
|
| 91 |
+
)
|
| 92 |
+
st.success("Password Saved Successfully!")
|
| 93 |
|
| 94 |
|
| 95 |
# Show saved passwords
|