this is first time i am posting to stackoverflow
what will be the efficient way to create and use such variables
lowerCharsEnabled = True
upperCharsEnabled = True
digitCharsEnabled = True
specialCharsEnabled = True
this function does the job but according to me its not the most efficient way of doing this
def usedChars():
global finalChars
if lowerCharsEnabled == True:
finalChars = lowerChars
if upperCharsEnabled == True:
finalChars = finalChars + upperChars
if digitCharsEnabled == True:
finalChars = finalChars + digitChars
if specialCharsEnabled == True:
finalChars = finalChars + specialChars
looking forward for suggestions any help would be appreciated
full program code for reference
import random
import string
lowerChars = string.ascii_lowercase
upperChars = string.ascii_uppercase
digitChars = string.digits
specialChars = string.punctuation
lowerCharsEnabled = True
upperCharsEnabled = True
digitCharsEnabled = True
specialCharsEnabled = True
finalChars = ""
passLen = 8
def usedChars():
global finalChars
if lowerCharsEnabled == True:
finalChars = lowerChars
if upperCharsEnabled == True:
finalChars = finalChars + upperChars
if digitCharsEnabled == True:
finalChars = finalChars + digitChars
if specialCharsEnabled == True:
finalChars = finalChars + specialChars
def generatePass():
try:
password = "".join(random.choice(finalChars) for x in range(passLen))
print(password)
except:
print("Cant Generate Pass")
usedChars()
generatePass()
input("Waiting...")