user account logon from python

Mike Meyer mwm at
Wed Nov 9 03:00:09 CET 2005

"Philippe C. Martin" <pmartin at> writes:
> Hi Mike,
> Mike Meyer wrote:
>>> 1- I cannot find getpwent in the documentation
>> getpwent is a Unix library call. For python, you want the pwd
>> module. The docs are <URL: >.
> I must be blind but still do not see it - do you mean getpwnam ?

Sorry, I wasn't clear about it. getpwent is a Unix call that lets you
walk through all the entries in the password file. The equivalent in
the pwd module is getpwall. For your usage, you probably want

>>> 2- crypt will not work if the system does not have shadow pw
>> Rubbish. crypt doesn't know anything about passord files. It just
>> knows how to encrypt a password. It's up to you to get the password
>> attempt from the user, and the encrypted password from the password
>> file (or the shadow password file). The pwd module doesn't deal with
>> shadow passwords. Maybe you meant "system does have shadow pw". But
>> it's pwd that doesn't work, not crypt - and that depends on the
>> system. For instance:
> I meant that the code form the documentation fails on the "raise", with the
> error "Sorry, currently no support for shadow passwords"
> What should I understand ?

Right. You meant the example fails if the system does have a shadow
password system.

There are two alternatives: One, you're not running as root, and the
system works like FreeBSD (where my example was run), whose pwd
library transparently handles the shadow password file, filling in
real passwords iff you're root. In that case, running as root will
solve the problem.

Two, your system has a different API for dealing with the shadow
password file. You'll either have to wrap that API, or parse the
shadow password file yourself. Either way, you'll have to run as root
to access the real password information.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list