samedi 2 janvier 2016

Pre-determined password is same as user input

My program needs to remember a specific pre-determined password which has been assigned to a variable so that the user input must match it.

import random

password = [chr(random.randint(33, 126)) for x in range(6)]

print("Your password is: {}".format(" ".join(password)))

import getpass

pswd = getpass.getpass(password)

if (pswd==password):
   print ("Access granted")
else:
   print ("Access denied")

In the code they receive their password and then they need to input it. I've removed a massive chunk of irrelevant coding and so the main thing is that the user gets their password and later on they have to input it. So the password is a set of random characters which then is the password that the user needs to remember and therefore input when required. It's not working and I was wondering if someone could help please. Also is there a way to remove the red writing that appears on the shell due to the importation of getpass.

Thanks




Aucun commentaire:

Enregistrer un commentaire