美好的一天。Python輸入密碼並與暗號密碼數據庫比較
我試着寫一個Python腳本,將捕獲的密碼,然後比較其 到系統陰影密碼。
我使用Ubuntu 12.10進行此測試。並以sudo的方式運行腳本。
def login(user, password):
"Check if user would be able to login using password"
try:
pw1 = spwd.getspnam(user)[1]
allus = spwd.getspall()
print pw1
# pw2 = crypt.crypt(password, pw1[:2])
pw2 = crypt.crypt(password, '\$6\$SALTsalt\$')
print pw2
return pw1 == pw2
except KeyError:
return 0 # no such user
現在上面回報
2 diferent密碼,但我得到從陰影的一個。
所以我的問題是如何加密提供的密碼,所以我可以把它比作一個 retreived。任何幫助將是要命
編輯插件
def login(user, password):
"Check if user would be able to login using password"
try:
pw1 = spwd.getspnam(user)[1]
allus = spwd.getspall()
# print allus
print pw1
# pw2 = crypt.crypt(password, pw1[:2])
# pw2 = crypt.crypt(password, '\$6\$SALTsalt\$')
pw2 =hashlib.new()
pw2.update(password)
pw2.digest()
print pw2
return pw1 == pw2
except KeyError:
return 0 # no such user
這也沒有工作 怎樣才能impliment的haslib獲得哈希匹配系統密碼
什麼是''\ $ 6''?它看起來像破碎的awk代碼,絕對不是有用的Python。 – msw 2013-04-06 04:21:24
我從另一個網站獲得的6美元收入表明它對於我認爲的sha-512有一定的幫助。頁面關閉,所以我可以查找。你知道一個不同的方式 – SAShapeShifter 2013-04-06 04:25:16
地穴只使用DES,它是舊的,而不是在Ubuntu中使用。相反,請查看http://docs.python.org/2/library/hashlib.html。 – msw 2013-04-06 04:29:01