-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordGenerator.py
More file actions
60 lines (45 loc) · 1.73 KB
/
Copy pathpasswordGenerator.py
File metadata and controls
60 lines (45 loc) · 1.73 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
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
import random
import string
def generate_password():
length = 12 # Fixed length for the password
# YOUR CODE GOES HERE
uppercase = string.ascii_uppercase
lowercase = string.ascii_lowercase
digits = string.digits
symbols = string.punctuation
# Function to generate a readable word
def generate_text_word():
word_length = 5 # Length of the readable word
word = ''.join(random.choices(lowercase + uppercase, k=word_length))
return word
# Function to generate a random symbol
def generate_random_symbol():
return random.choice(symbols)
# Function to generate a random digit
def generate_random_digit():
return random.choice(digits)
# Generate the readable word
text_word = generate_text_word()
# Ensure the password is exactly 12 characters long by adjusting the number of symbols and digits added
remaining_length = length - len(text_word)
assert remaining_length == 7, "Ensure the fixed length of 12 characters is maintained"
password = (
generate_random_symbol() +
generate_random_digit() +
text_word +
''.join(random.choices(digits + symbols, k=remaining_length - 2))
)
return password
print("Password generated successfully, Following the 3 rules:")
print("\n1. The password string should....")
print("Contains uppercase and lowercase letter")
print("\n2. The password string should....")
print("At least one number and one symbol entered")
print("\n3. The password string should....")
print("Can't enter pattern's like: \"123, abc\"\n")
'''
# Do not change the code below
'''
# Generate a password that meets the criteria
password = generate_password()
print("Generated Password:", password)