checking user passwords

Davide Alberani alberanid at
Tue Mar 28 12:38:57 CEST 2000

"Pete Shinners" <pete at> wrote:
> under unix i'd like to verify a username and password.

I think you've to use pwd and crypt modules.

A really poor example:


import pwd, crypt

uname = raw_input('Your username: ')
passwd = raw_input('Password: ')

# Here a KeyError exception may be raised.
pw = pwd.getpwnam(uname)[1]

crp = crypt.crypt(passwd, pw[:2])

if crp == pw:
    print 'Ok!'
    print 'Error!'


I'm not sure it works with shadow password.

Cinereview: Il Talento di Mr.Ripley: ottimo intreccio, buoni _/Davide\_
interpreti e regia.  Voto: 8.5                               \Alberani/

More information about the Python-list mailing list