-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_generator.py
64 lines (46 loc) · 1.54 KB
/
password_generator.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import random
import string
import streamlit as st
st.title('Password Generator')
if st.checkbox('Do you want to have numbers?'):
has_number = True
else:
has_number = False
if st.checkbox('Do you want to have special characters?'):
has_special = True
else:
has_special = False
def generate_password(min_length, has_number, has_special):
letters = string.ascii_letters
digits = string.digits
special = string.punctuation
characters = letters
if has_number:
characters += digits
if has_special:
characters += special
pwd = ""
# at least one number if so chosen
if has_number:
new_number = random.choice(digits)
pwd += new_number
# at least one special character if so chosen
if has_special:
new_special = random.choice(special)
pwd += new_special
while len(pwd) < min_length:
new_char = random.choice(characters)
pwd += new_char
return pwd
min_length = st.slider('Minimal Length', 12, 60, 20) # min, max, default
pwd = generate_password(min_length, has_number, has_special)
st.subheader('Password')
st.write(pwd)
footer_html = """<div style='text-align: center;'>
<p><a href="https://github.com/italojsoliveira/password-generator">Source Code</a></p>
</div>"""
st.markdown(footer_html, unsafe_allow_html=True)
footer_html = """<div style='text-align: center;'>
<p>Developed with ❤️ by <a href="https://italojsoliveira.github.io/">Ítalo Oliveira</a></p>
</div>"""
st.markdown(footer_html, unsafe_allow_html=True)