参考pwd
— The password database和href=http://www.python.org/doc/current/lib/module-crypt.html>crypt — Function to
check Unix passwords,而且原文有一个例子:
import crypt, getpass, pwd
def login():
username = raw_input(‘Python login:’)
cryptedpasswd = pwd.getpwnam(username)[1]
if cryptedpasswd:
if cryptedpasswd == ‘x’ or cryptedpasswd == ‘*’:
raise “Sorry, currently no support for shadow passwords”
cleartext = getpass.getpass()
return crypt.crypt(cleartext, cryptedpasswd[:2]) == cryptedpasswd
else:
return 1
注意:例子中也提到了,现在还不支持shadow了的密码提取。
ps. 还有点话想说:这两个问题在Python Lib Ref里可以很容易的找到
解决办法,而且Python安装后都有这些手册,希望你能够善用!