0
我正在使用Flask和MongoDB,嘗試使用passlib實現用戶名/密碼驗證。python passlib驗證不匹配
從models.py類:
from passlib.hash import sha256_crypt
class Users(object):
def __init__(self, username='', password='', collection=db.users, articles=''):
self.collection = collection
self.username = username
self.password = password
self.articles = []
def addUser(self):
self.collection.insert({'username': self.username, 'password': sha256_crypt.encrypt('self.password'), 'articles': self.articles})
從Python的外殼,我創建了用戶Alice,密碼爲 '祕密':
>>> import models
>>> alice = models.Users()
>>> alice.username = 'alice'
>>> alice.password = 'secret'
>>> alice.addUser()
從蒙戈外殼,我檢查該文件已經很好地用散列代替明文密碼創建:
> db.users.find()
{ "_id" : ObjectId("57f15d9f815a0b6c1533427f"), "username" : "alice", "articles" : [ ], "password" : "$5$rounds=535000$Oq1hy1INzO59nu0q$FzMz1DtBWDwM.sw0AhrlVA8esgE30n8rr/NjOltB8.7" }
從現在開始,我們應該能夠使用存儲在文檔中的哈希驗證來自python shell的密碼,不是嗎?
>>> sha256_crypt.verify('secret','$5$rounds=535000$Oq1hy1INzO59nu0q$FzMz1DtBWDwM.sw0AhrlVA8esgE30n8rr/NjOltB8.7')
False
但它沒有,有人可以向我解釋爲什麼?
神,這麼明顯XDXD - 謝謝你! – Kuruwan