我想創建一個用戶在控制檯中輸入密碼的小程序。然後,程序根據用戶輸入的內容檢查密碼是弱,中或強。Python - 檢查數字,大寫,小寫字母和特殊字符的輸入
我需要檢查輸入了多少個大寫,小寫和數字,然後告訴用戶密碼的強度。
我已經完成了大部分程序,但由於我沒有真正使用過Python,所以我不太熟悉任何先進的東西,請記住,年輕人也必須理解這些代碼,這些代碼不會很好在編碼自己。
到目前爲止,我有:
#Welcome the user to the application.
print("Hello, please enter a password to check how secure it is");
#Set a variable called MinPass and set a value of 6.
MinPass = 6;
#Set a variable called MaxPass and set a value of 12.
MaxPass = 12;
#Set variable EnteredPass and wait for user input
EnteredPass = input("Password: ");
while len(EnteredPass) < MinPass:
print("Your password is too short, please enter a longer password and try again")
EnteredPass = input("Password: ");
while len(EnteredPass) > MaxPass:
print("Your password is too long, please shorten it and try again!");
EnteredPass = input("Password: ");
請注意,這僅僅是爲了教育目的。我不打算製作一個旨在竊取隨機密碼的程序。這是我校學習課程的一部分!
你還沒有做出很多嘗試,你呢?你有沒有看過['str'類型方法](http://docs.python.org/2/library/stdtypes.html#string-methods)? –
@MartijnPieters他們已經設置了一些變量:)我只是想知道什麼是「womabt」是:) –
雖然,我已經回答了您的問題,並且有更多的人可以回答這些問題,我會建議您在提問關於SO的問題之前,先看一下python的文檔(或者你正在學習的語言)。即使是最好的程序員,也要繼續參考語言的文檔。另外,python提供的文檔非常好。 –