美好的一天。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