Skip to content

Commit

Permalink
feat: generate breached passwords script
Browse files Browse the repository at this point in the history
  • Loading branch information
ni-jessica committed Oct 15, 2023
1 parent f19306e commit 0154168
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions backend/database/generatePasswords.py
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)

0 comments on commit 0154168

Please sign in to comment.