I am supposed to write a script with the following criteria: Write a function called validatePassword that takes a password string as a parameter and returns true or false. The function should only return true if:
- The password is at least 8 characters
- The password contains at least one number
- The password contains at least one upper case letter. Hint: use the isupper() string function.
- The password contains a symbol one of the symbols !@#$%^&*()+=
I have this so far:
def validatePassword(pswd):
if len(pswd)> 8:
return True
else:
return False
for char in pswd:
if char in '01234567890':
return True
else:
return False
for char in pswd:
if char in '!@#$%^&*()_+=':
return True
else:
return False
for char in pswd:
if char.isupper and char .islower:
return True
else:
return False
return True
while False:
print("There was an error with your password")
print (validatePassword(Herseuclds))
I know that print (validatePassword(Herseuclds)) has a syntax error because I am missing the variable but I just don't get how to do this.
print (validatePassword("Herseuclds"))to make "Herseuclds" a string literal. Otherwise it's treated as a variable name likecharand andpswd, but you haven't defined it anywhere as a variable, so it has no value and doesn't make sense. You also need to remove the space inchar .islowerand add parentheses so you call the methods, i.e.char.islower()andchar.isupper(). And you don't want toreturn Truereturn Falseall the time, or you'll only do the length check and not get to any of the other checks.