Skip to content

Commit 0147141

Browse files
Merge pull request #2719 from ivanho-git/patch-1
Update passwordGenerator.py
2 parents e34181a + b5e1a16 commit 0147141

File tree

1 file changed

+44
-120
lines changed

1 file changed

+44
-120
lines changed
Lines changed: 44 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,49 @@
11
# PasswordGenerator GGearing 314 01/10/19
22
# modified Prince Gangurde 4/4/2020
33

4-
from random import randint
4+
import random
55
import pycountry
66

7-
case = randint(1, 2)
8-
number = randint(1, 999)
9-
10-
# TODO: Pick random country from it
11-
12-
countries = list(pycountry.countries)
13-
country_names = [country.name for country in countries]
14-
15-
print(country_names)
16-
17-
# TODO: Try to add languages, too.
18-
19-
specialCharacters = (
20-
"!",
21-
"@",
22-
"#",
23-
"$",
24-
"%",
25-
"/",
26-
"?",
27-
":",
28-
"<",
29-
">",
30-
"|",
31-
"&",
32-
"*",
33-
"-",
34-
"=",
35-
"+",
36-
"_",
37-
)
38-
39-
animals = (
40-
"ant",
41-
"alligator",
42-
"baboon",
43-
"badger",
44-
"barb",
45-
"bat",
46-
"beagle",
47-
"bear",
48-
"beaver",
49-
"bird",
50-
"bison",
51-
"bombay",
52-
"bongo",
53-
"booby",
54-
"butterfly",
55-
"bee",
56-
"camel",
57-
"cat",
58-
"caterpillar",
59-
"catfish",
60-
"cheetah",
61-
"chicken",
62-
"chipmunk",
63-
"cow",
64-
"crab",
65-
"deer",
66-
"dingo",
67-
"dodo",
68-
"dog",
69-
"dolphin",
70-
"donkey",
71-
"duck",
72-
"eagle",
73-
"earwig",
74-
"elephant",
75-
"emu",
76-
"falcon",
77-
"ferret",
78-
"fish",
79-
"flamingo",
80-
"fly",
81-
"fox",
82-
"frog",
83-
"gecko",
84-
"gibbon",
85-
"giraffe",
86-
"goat",
87-
"goose",
88-
"gorilla",
89-
)
90-
91-
colour = (
92-
"red",
93-
"orange",
94-
"yellow",
95-
"green",
96-
"blue",
97-
"indigo",
98-
"violet",
99-
"purple",
100-
"magenta",
101-
"cyan",
102-
"pink",
103-
"brown",
104-
"white",
105-
"grey",
106-
"black",
107-
)
108-
109-
chosenanimal = animals[
110-
randint(0, len(animals) - 1)
111-
] # randint will return max lenght but , tuple has index from 0 to len-1
112-
chosencolour = colour[randint(0, len(colour) - 1)]
113-
chosenSpecialCharacter = specialCharacters[randint(0, len(specialCharacters) - 1)]
114-
115-
if case == 1:
116-
chosenanimal = chosenanimal.upper()
117-
print(chosencolour + str(number) + chosenanimal + chosenSpecialCharacter)
118-
else:
119-
chosencolour = chosencolour.upper()
120-
print(chosenanimal + str(number) + chosencolour + chosenSpecialCharacter)
121-
122-
# Try to consolidate unify the characters.
123-
124-
125-
# The program can be further improved.
7+
def generate_password():
8+
# Define characters and word sets
9+
special_characters = list("!@#$%/?<>|&*-=+_")
10+
11+
animals = (
12+
"ant", "alligator", "baboon", "badger", "barb", "bat", "beagle", "bear", "beaver", "bird",
13+
"bison", "bombay", "bongo", "booby", "butterfly", "bee", "camel", "cat", "caterpillar",
14+
"catfish", "cheetah", "chicken", "chipmunk", "cow", "crab", "deer", "dingo", "dodo", "dog",
15+
"dolphin", "donkey", "duck", "eagle", "earwig", "elephant", "emu", "falcon", "ferret", "fish",
16+
"flamingo", "fly", "fox", "frog", "gecko", "gibbon", "giraffe", "goat", "goose", "gorilla"
17+
)
18+
19+
colours = (
20+
"red", "orange", "yellow", "green", "blue", "indigo", "violet", "purple",
21+
"magenta", "cyan", "pink", "brown", "white", "grey", "black"
22+
)
23+
24+
# Get random values
25+
animal = random.choice(animals)
26+
colour = random.choice(colours)
27+
number = random.randint(1, 999)
28+
special = random.choice(special_characters)
29+
case_choice = random.choice(["upper_colour", "upper_animal"])
30+
31+
# Pick a random country and language
32+
country = random.choice(list(pycountry.countries)).name
33+
languages = [lang.name for lang in pycountry.languages if hasattr(lang, "name")]
34+
language = random.choice(languages)
35+
36+
# Apply casing
37+
if case_choice == "upper_colour":
38+
colour = colour.upper()
39+
else:
40+
animal = animal.upper()
41+
42+
# Combine to form password
43+
password = f"{colour}{number}{animal}{special}"
44+
print("Generated Password:", password)
45+
print("Based on Country:", country)
46+
print("Language Hint:", language)
47+
48+
# Run it
49+
generate_password()

0 commit comments

Comments
 (0)