python_hashlib,md5,getpass, 密碼加密,隱藏,加鹽

Lutos發表於2019-06-19
# coding = utf-8
import hashlib
import getpass
LIST_01 = []


def registers():
print("請按提示建立使用者資訊")
while True:
print("(提示:輸入使用者名稱為 N/n時,退出輸入)")
name = input("輸入使用者名稱")
if name.upper() == "N":
break
pwd = getpass.getpass("密碼")
password = get_md5(pwd)
temp = {"user_name": name, "password": password}
LIST_01.append(temp)


def get_md5(data):
obj = hashlib.md5("wenxing".encode("utf-8"))
obj.update(data.encode("utf-8"))
password = obj.hexdigest()
return password


def login():
print("**********登入************")
user = input("使用者名稱")
pwd = getpass.getpass("密碼")

for item in LIST_01:
if item["user_name"] == user and item["password"] == get_md5(pwd):
return True


registers()
print(LIST_01)
result = login()
if result:
print("成功")
else:
print("失敗")

相關文章