Skip to content

Commit

Permalink
Update PasswordGenerator.py
Browse files Browse the repository at this point in the history
- Added more comments
- Fixed a bug: The first letter in words from passphrases wouldn't be capitalized
  • Loading branch information
Wolfmyths authored Nov 17, 2022
1 parent 30daf67 commit 6fe6840
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions PasswordGenerator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import requests
import urllib3 # Added so py installer could find the correct modules
class password:
def __init__(self, strength='strong', length=0, capital='true'):
self.strength = strength
Expand All @@ -21,19 +22,19 @@ def get_pass(self):

for i in range(length):

charChoice = self.charChoice[random.randint(0, 2)] if self.strength == 'strong' else self.charChoice[random.randint(0, 1)] #If the strength is set to strong it will include the index value for symbols
i = charChoice[random.randint(0, (len(charChoice) - 1))] # subtracts 1 from the list length to compensate lists in python being starting sub 0
charChoice = self.charChoice[random.randint(0, 2)] if self.strength == 'strong' else self.charChoice[random.randint(0, 1)] # If the strength is set to strong it will include the index value for symbols
i = charChoice[random.randint(0, (len(charChoice) - 1))] # Subtracts 1 from the list length to compensate lists in python being starting sub 0

if self.capital == 'true' and i in self.alphabet: #If statement checks if the character can be capitalised
if random.randint(0, 1) == 1: #Coin flip
if self.capital == 'true' and i in self.alphabet: # If statement checks if the character can be capitalised
if random.randint(0, 1) == 1: # Coin flip
i = i.upper()

password += i

return password

class passphrase:
def __init__(self, length=0, capitalize='false'):
def __init__(self, length=0, capitalize=''):
self.length = length
self.capitalize = capitalize

Expand All @@ -47,14 +48,14 @@ def get_phrase(self):
return f'The length "{length}" is too high, use 250 or below'

for i in range(length):
word = requests.get('https://random-word-api.herokuapp.com/word')
word = requests.get('https://random-word-api.herokuapp.com/word') # Access the random word API
word = word.text
word = word[2:-2]
word = word[2:-2] # word.text has brackets and quotations around it ( ["Example"] ) , this line removes those
if self.capitalize == 'true':
word.title()
if password == '':
word = word.title()
if password == '': # If statement determines if the word being added to the passphrase is the first word
password += word
else:
password += f' {word}'

return password
return password

0 comments on commit 6fe6840

Please sign in to comment.