Personal tools
Document Actions

password

Up to table of contents

This FAQ applies to: Any version.

How do I check unix password?
import pwd, crypt

def login(user, password):
"Check if user would be able to login using password"
try:
pw1 = pwd.getpwnam(user)[1]
pw2 = crypt.crypt(password, pw1[:2])
return pw1 == pw2
except KeyError:
return 0 # no such user

user = raw_input("username:")
password = raw_input("password:")

if login(user, password):
print "welcome", user
else:
print "login failed"
by yongzhao — last modified 2006-11-04 14:17 Molecular Graphics Laboratory, TSRI

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: