36 lines
890 B
Python
36 lines
890 B
Python
from random import randint
|
|
from string import ascii_letters, digits
|
|
|
|
spChars = "+-*/?!"
|
|
|
|
|
|
def insert(string, char, index):
|
|
return string[0:index] + char + string[index+1:len(string)]
|
|
|
|
|
|
|
|
def randomCharFromArray(array):
|
|
return array[randint(0,len(array)-1)]
|
|
|
|
|
|
def makePassword(length):
|
|
password = ""
|
|
|
|
for _ in range(length):
|
|
password += randomCharFromArray(ascii_letters)
|
|
|
|
randIndex1 = randint(0,len(password)-1)
|
|
password = insert(password, randomCharFromArray(digits), randIndex1) #[randIndex1] = randomCharFromArray(digits)
|
|
|
|
randIndex2 = randint(0,len(password)-2)
|
|
if randIndex1 == randIndex2:
|
|
randIndex2 = len(password) - 1
|
|
password = insert(password, randomCharFromArray(spChars), randIndex2)
|
|
return password
|
|
|
|
|
|
def main():
|
|
length = int(input("Insert password length"))
|
|
print("Your password is", makePassword(length))
|
|
|
|
main() |