31
loading...
This website collects cookies to deliver better user experience
try:
num_of_numbers = int(input("How many numbers should your password have: "))
except ValueError:
num_of_numbers = int(input("How many numbers should your password have: "))
try:
num_of_special = int(
input("How many special characters should your password have: "))
except ValueError:
num_of_special = int(
input("How many special characters should your password have: "))
try:
num_of_small_letters = int(
input("How many small letters should your password have: "))
except ValueError:
num_of_small_letters = int(
input("How many small letters should your password have: "))
try:
num_of_cap_letters = int(
input("How many big letters should your password have: "))
except ValueError:
num_of_cap_letters = int(
input("How many big letters should your password have: "))
number_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
But this will take us way more time!
So let's use the string module!
import string
number_list = list(string.digits)
import string
smallLetters = list(string.ascii_lowercase)
bigLetters = list(string.ascii_uppercase)
specialCharacters = list(string.punctuation)
numbers = list(string.digits)
spPart = ""
numPart = ""
smallPart = ""
bigPart = ""
for i in range(1, num_of_numbers + 1):
randNum = secrets.choice(numbers)
numPart = numPart + str(randNum)
for i in range(1, num_of_special + 1):
randSp = secrets.choice(specialCharacters)
spPart = spPart + randSp
for i in range(1, num_of_small_letters + 1):
randSm = secrets.choice(smallLetters)
smallPart = smallPart + randSm
for i in range(1, num_of_cap_letters + 1):
randBig = secrets.choice(bigLetters)
bigPart = bigPart + randBig
password = numPart + spPart + smallPart + bigPart
def generate_password( num_of_numbers, num_of_special, num_of_small_letters, num_of_cap_letters):
smallLetters = list(string.ascii_lowercase)
bigLetters = list(string.ascii_uppercase)
specialCharacters = list(string.punctuation)
numbers = list(string.digits)
spPart = ""
numPart = ""
smallPart = ""
bigPart = ""
# ANCHOR: Generating Password
for i in range(1, num_of_numbers + 1):
randNum = secrets.choice(numbers)
numPart = numPart + str(randNum)
for i in range(1, num_of_special + 1):
randSp = secrets.choice(specialCharacters)
spPart = spPart + randSp
for i in range(1, num_of_small_letters + 1):
randSm = secrets.choice(smallLetters)
smallPart = smallPart + randSm
for i in range(1, num_of_cap_letters + 1):
randBig = secrets.choice(bigLetters)
bigPart = bigPart + randBig
password = numPart + spPart + smallPart + bigPart
return password