用户如何输入加密的密码? PYTHON3

时间:2017-05-24 15:37:17

标签: python-3.x sqlite encryption hash

我已将PIN密码加密到数据库中。我使用散列完成了此操作,并保存在变量actualPIN下输入的PIN:

 actualPIN = str(actualPIN)
    PIN = hashlib.md5() 
    PIN.update((actualPIN).encode('utf-8'))
    data = (rollingBalance, actualPIN, ID)
    print(rollingBalance)
    with sqlite3.connect("ATM.db") as db:
        cursor = db.cursor()
        sql = 'update Atm set Balance=?, PIN=? where CustomerID=?'
        cursor.execute(sql, data)
        db.commit()

现在,这样可以正常工作并将加密的PIN保存为'81dc9bdb52d04dc20036dbd8313ed055',这是'1234'的加密(更改引脚前的默认PIN是9999,最初在数据库中保存为9999) 。现在,当我回到开始并尝试输入'1234'引脚时,我被告知这是无效的,实际引脚是上面提供的加密。我现在的猜测是更改我输入引脚的代码以尝试将此匹配加密,但我不确定这是否正确,因为我不知道如何解密消息。在数据库上输入PIN的代码如下:

with sqlite3.connect("ATM.db") as db:
            cursor = db.cursor()
            cursor.execute("select Balance from Atm where CustomerID=?",(ID,))
            balance = cursor.fetchone()
            rollingBalance = (balance[0])
        print("You must now enter in your PIN")
        with sqlite3.connect("ATM.db") as db:
            cursor = db.cursor()
            cursor.execute("select PIN from Atm where CustomerID=?",(ID,))
            PIN = cursor.fetchone()
            actualPIN = (PIN[0]) 
        print(actualPIN)
        loggedIN = False
        while loggedIN == False:
            answer = (input("Please enter your pin"))
            if answer == str(actualPIN):
                loggedIN = True
                mainMenu(name, ID, rollingBalance, actualPIN)
            else:
                print("That is incorrect")

0 个答案:

没有答案
相关问题