forked from devops01ua/python01-hw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordgenerator
More file actions
31 lines (26 loc) · 1.21 KB
/
passwordgenerator
File metadata and controls
31 lines (26 loc) · 1.21 KB
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
import random
import string
def generate_password(length):
# Define character sets for password generation
uppercase_letters = string.ascii_uppercase
lowercase_letters = string.ascii_lowercase
numbers = string.digits
special_characters = string.punctuation
# Ensure the generated password meets the required criteria
while True:
password = random.choices(uppercase_letters, k=1) + \
random.choices(lowercase_letters, k=1) + \
random.choices(numbers, k=1) + \
random.choices(special_characters, k=1) + \
random.choices(uppercase_letters + lowercase_letters + numbers + special_characters, k=length-4)
password = ''.join(password)
if (any(char.isupper() for char in password) and
any(char.islower() for char in password) and
any(char.isdigit() for char in password) and
any(char in special_characters for char in password)):
break
return password
print("Welcome to the Linux User Password Generator!")
length = int(input("Please enter the desired password length: "))
password = generate_password(length)
print("\nGenerated password:", password)