-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.py
122 lines (113 loc) · 2.78 KB
/
colors.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# A couple different color based ones
import random
color_choice = random.choice(
["FF0000", "00FF00", "0000FF", "FFFF00", "00FFFF", "FF00FF"]
) # Red Green Blue Yellow Cyan Magenta
# Must contain only two primary colors
def primary(i, password):
# Check if password has primary color
x = 0
for color in ["blue", "red", "green"]:
if color in password.lower():
x += 1
# Pass check
if x == 2:
return True
# Did not pass
if x == 1:
print(
"Rule "
+ str(i)
+ ": Password must include one more primary color (Science/Computing based primary colors)."
)
elif x > 2:
print(
"Rule "
+ str(i)
+ ": Password must include only two primary colors (Science/Computing based primary colors)."
)
else:
print(
"Rule "
+ str(i)
+ ": Password must include two primary colors (Science/Computing based primary colors)."
)
return False
# Must contain the mix of the two primary colors
def secondary(i, password):
# Get the first 2 primary colours
colors = []
for color in ["blue", "red", "green"]:
if color in password.lower():
if color not in colors and len(colors) < 2:
colors.append(color)
# Decide what the mixture is
x = []
if "blue" in colors and "red" in colors:
x = ["magenta", "purple", "pink", "lilac", "violet"]
elif "red" in colors and "green" in colors:
x = ["yellow"]
elif "green" in colors and "blue" in colors:
x = ["cyan", "turquoise"]
# Test if mixture is in password
for y in x:
if y in password.lower():
return True
# Did not pass
print(
"Rule "
+ str(i)
+ ": Password must include the mixture of your two primary colors."
)
return False
# Must only contain a single secondary color
def multiplesecondary(i, password):
# Count up each color
t = 0
for c in [
"magenta",
"purple",
"pink",
"lilac",
"violet",
"yellow",
"cyan",
"turquoise",
]:
if c in password.lower():
t += 1
# Test if there is less than or equal to 1 in total
if t <= 1:
return True
# Did not pass
print("Rule " + str(i) + ": Password must only contain a single secondary color.")
return False
# Must contain this color in text
def hextotext(i, password):
# Setup choices
choices = []
if color_choice == "FF0000":
choices = ["red"]
elif color_choice == "00FF00":
choices = ["green"]
elif color_choice == "0000FF":
choices = ["blue"]
elif color_choice == "FFFF00":
choices = ["yellow"]
elif color_choice == "00FFFF":
choices = ["cyan", "turquoise"]
elif color_choice == "FF00FF":
choices = ["magenta", "purple", "pink", "lilac", "violet"]
# For each choice test if it is in password
for color in choices:
if color in password.lower():
return True
# Did not pass
print(
"Rule "
+ str(i)
+ ": Password must include the name of the color #"
+ color_choice
+ " (That is hexadecimal rgb)."
)
return False