jeudi 8 avril 2021

input isn't choosing the passwort length

I'm new to programming, and I'm making a password manager. My problem: -what it does -> when I run the program and enter the length of the password it generates a password, but it is always 4 digits long and the password gets repeated so many times as the digit I had put in. -What it should do -> the digit that I put in should determine the length of the password and not how many times it gets repeated.

import random

#shuffle the list
def shuffle(string):
  tempList = list(string)
  random.shuffle(tempList)
  return ''.join(tempList)

#the password functions
uppercaseLetter=chr(random.randint(65,90))
lowercaseLetter=chr(random.randint(97,122))
punctuationSign=chr(random.randint(32,152))
digit=chr(random.randint(48,57))

#completing the password
passwordLength = int(input("choose your password length: "))

possibleChars = uppercaseLetter, lowercaseLetter, punctuationSign, digit
ranChar = shuffle(possibleChars)

tempPassword = []

count = 0
while count != passwordLength:
    tempPassword.extend(ranChar)
    count = count + 1

password = ''.join(tempPassword)

#for which sitename
sitename = input('Save under which name: ')


print (password, sitename)

data=open("test.txt",'a')
data.write(sitename +'  ')
data.write(password +'\n')
data.close()



Aucun commentaire:

Enregistrer un commentaire