-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate breached passwords script
- Loading branch information
1 parent
f19306e
commit 0154168
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import random | ||
import string | ||
import csv | ||
|
||
''' | ||
Generates 20 passwords between 10-24 characters that contain: | ||
- at least 1 lowercase letter | ||
- at least 1 uppercase letter | ||
- at least 1 digit | ||
- 1 special character | ||
since when presented with these requirements, most users choose 1 special character and fill in the rest of the characters with letters and digits. Writes to passwords to a csv file. | ||
''' | ||
passwords, i = [], 0 | ||
while i < 20: | ||
# meet requirements: | ||
password = random.choice(string.ascii_lowercase) # select 1 lowercase | ||
password += random.choice(string.ascii_uppercase) # select 1 uppercase | ||
password += random.choice(string.digits) # select 1 digit | ||
password += random.choice(string.punctuation) # select 1 special symbol | ||
|
||
# generate other characters | ||
random_source = string.ascii_letters + string.digits | ||
r = random.randint(6,20) | ||
for _ in range(r): | ||
password += random.choice(random_source) | ||
|
||
# shuffle all characters | ||
password_list = list(password) | ||
random.SystemRandom().shuffle(password_list) | ||
password = ''.join(password_list) | ||
|
||
if password not in passwords: | ||
passwords.append(password) | ||
i += 1 | ||
|
||
# write to csv file | ||
with open('./backend/database/breachedPasswords.csv', 'w', newline='') as csvfile: | ||
writer = csv.writer(csvfile, delimiter = '\n') | ||
writer.writerow(passwords) |