2017-10-07 2 views
-5

私の割り当ては、3人のユーザ(Alice、Bob、Charles)のうちの1人が希望するパスワードを入力できるPythonプログラムを設計することです。私のプログラムは、それが有効なパスワードかどうかを判断します。さらに、私のプログラムでは、過去にこのパスワードをすでに使用しているかどうかを確認し、以前にこのパスワードを使用していた場合はエラーメッセージを返します。ユーザ名/パスワードチェッカーでエラーが発生しました

私はユーザー名とパスワードの条件文を正しく書いていますが、ユーザーがパスワードを入力したとき、または入力していないときに無効な有効なメッセージを返すようなコードを得ることはできません。

user = input("Which user is this? ") 
if user == "Alice" or user == "Bob" or user == "Charles": 
    print("Welcome, ",user,"!",sep="") 
else: 
    print("I don't recognize that username. Please try again.") 

def checkPassword(pw): 
    errorMessage = '' 

if ((len(pw) > 20)): 
    errorMessage += "--Password is too long. 20 characters is the max.\n" 
elif (len(pw) < 12): 
    errorMessage += "--Password is too short. 12 characters is the min.\n" 

if pw.isalpha(): 
    errorMessage += "--Password needs at least one digit.\n" 

if pw.isdigit(): 
    errorMessage += "--Password needs at least one letter.\n" 

if pw.isupper(): 
    errorMessage += "--Password needs an uppercase character.\n" 

if pw.islower(): 
    errorMessage += "--Password needs a lowercase character.\n" 

if pw.isalnum(): 
    errorMessage += "--Password needs a punctuation character.\n" 

return errorMessage 

passwordCandidate = input("Please input a valid password: ") 
errors = '' 

errors = checkPassword(passwordCandidate) 

if errors is not '': 
    print("Your password is invalid:\n", errors, sep='') 

elif user == "Alice" and passwordCandidate == "IamAlice123!" and 
passwordCandidate == "Alicerules99!" and passwordCandidate == 
"ILo^eBob2017" and passwordCandidate == "pa%%word2017": 
    print("--It appears that you have used this password before. Please 
choose another one.") 

elif user == "Bob" and passwordCandidate == "MyNameIs808,FearMe" and 
passwordCandidate == "[email protected]@@" and passwordCandidate == 
"iamthe#1bestatLIFE" and passwordCandidate == "2Busy2BeTiedDown!":  
    print("--It appears that you have used this password before. Please 
choose another one.") 

elif user == "Charles" and passwordCandidate == "Alice5uxAlice5ux!" and 
passwordCandidate == "GoAwayYuckyAlice" and passwordCandidate == 
"!secretlyLuvBob99" and passwordCandidate == "[email protected]~~~": 
    print("--It appears that you have used this password before. Please 
choose another one.") 

else: 
    print("Your password is valid.")  

Photo of code

答えて

0

あなたは既に使用され、パスワードのorオペレータにandオペレータを変更し、括弧内にそれを囲む必要があります。

elif user == "Alice" and (passwordCandidate == "IamAlice123!" or passwordCandidate == "Alicerules99!" or passwordCandidate == "ILo^eBob2017" or passwordCandidate == "pa%%word2017"): 
    print("--It appears that you have used this password before. Please choose another one.") 
関連する問題