├── .idea
├── .gitignore
├── .name
├── Password_Generator.iml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
└── modules.xml
├── README.md
└── main.py
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Password_Generator
--------------------------------------------------------------------------------
/.idea/Password_Generator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Generate Password by using Python
2 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import random
2 | import array
3 |
4 | # maximum length of password needed
5 | # this can be changed to suit your password length
6 | MAX_LEN = 12
7 |
8 | # declare arrays of the character that we need in out password
9 | # Represented as chars to enable easy string concatenation
10 | DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
11 | LOCASE_CHARACTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
12 | 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q',
13 | 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
14 | 'z']
15 |
16 | UPCASE_CHARACTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
17 | 'I', 'J', 'K', 'M', 'N', 'O', 'P', 'Q',
18 | 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
19 | 'Z']
20 |
21 | SYMBOLS = ['@', '#', '$', '%', '=', ':', '?', '.', '/', '|', '~', '>',
22 | '*', '(', ')', '<']
23 |
24 | # combines all the character arrays above to form one array
25 | COMBINED_LIST = DIGITS + UPCASE_CHARACTERS + LOCASE_CHARACTERS + SYMBOLS
26 |
27 | # randomly select at least one character from each character set above
28 | rand_digit = random.choice(DIGITS)
29 | rand_upper = random.choice(UPCASE_CHARACTERS)
30 | rand_lower = random.choice(LOCASE_CHARACTERS)
31 | rand_symbol = random.choice(SYMBOLS)
32 |
33 | # combine the character randomly selected above
34 | # at this stage, the password contains only 4 characters but
35 | # we want a 12-character password
36 | temp_pass = rand_digit + rand_upper + rand_lower + rand_symbol
37 |
38 | # now that we are sure we have at least one character from each
39 | # set of characters, we fill the rest of
40 | # the password length by selecting randomly from the combined
41 | # list of character above.
42 | for x in range(MAX_LEN - 4):
43 | temp_pass = temp_pass + random.choice(COMBINED_LIST)
44 |
45 | # convert temporary password into array and shuffle to
46 | # prevent it from having a consistent pattern
47 | # where the beginning of the password is predictable
48 | temp_pass_list = array.array('u', temp_pass)
49 | random.shuffle(temp_pass_list)
50 |
51 | # traverse the temporary password array and append the chars
52 | # to form the password
53 | password = ""
54 | for x in temp_pass_list:
55 | password = password + x
56 |
57 | # print out password
58 | print(password)
--------------------------------------------------------------------------------