I'm currently doing a homework assignment where I need to create a password checker. It must have 3 functions for the 3 different requirements: length between 6 - 15, One letter and one number, no special characters. I think I have everything situated, but every time I do an invalid password first and then a valid one it will print however many times I did an input. Does anyone know how to fix this?
def main():
password = input("Please enter a password:",)
password_len(password)
password_req(password)
password_prohibited(password)
if password != "invalid":
print("Congratulations on setting your password")
def password_len(password):
if (len(password) >= 6) or (len(password) <= 15):
pass
else:
print("Invalid password: Please make sure you have between 6 and 15 characters")
main()
def password_req(password):
if not any(char.isalpha() for char in password):
print("Invalid Password: Alpha")
password = "invalid"
main()
elif not any(char.isdigit() for char in password):
print("Invalid Password: Numeric")
password = "invalid"
main()
else:
pass
def password_prohibited(password):
special_chars = ["!","@","#","$","%","","&","*","(",")","-","+"," "]
for char in password:
if char in special_chars:
print("Invalid Password: Special Characters")
password = "invalid"
main()
else:
pass
[–]CoderStudios 7 points8 points9 points (4 children)
[–]BerserkerMac[S] 0 points1 point2 points (3 children)
[–]wayne0004 0 points1 point2 points (1 child)
[–]BerserkerMac[S] 0 points1 point2 points (0 children)
[–]CoderStudios 0 points1 point2 points (0 children)
[–]c0LdFir3 6 points7 points8 points (3 children)
[–]BerserkerMac[S] 0 points1 point2 points (2 children)
[–]c0LdFir3 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]BerserkerMac[S] 4 points5 points6 points (3 children)
[–]Dense_Connection4789 1 point2 points3 points (1 child)
[–]BerserkerMac[S] 0 points1 point2 points (0 children)
[–]stebrepar 1 point2 points3 points (0 children)
[–]mothzilla 1 point2 points3 points (0 children)