GNU Info

Info Node: (python2.1-lib.info)crypt

(python2.1-lib.info)crypt


Next: dl Prev: grp Up: Unix Specific Services
Enter node , (file) or (file)node

Function to check UNIX passwords
================================

The `crypt()' function used to check UNIX passwords.  This module was
written by Steven D. Majewski <sdm7g@virginia.edu>.
This manual section was written by Steven D. Majewski
<sdm7g@virginia.edu>.
This manual section was written by Peter Funk <pf@artcom-gmbh.de>.
This module implements an interface to the `crypt(3)'  routine, which
is a one-way hash function based upon a modified DES  algorithm; see
the UNIX man page for further details.  Possible uses include allowing
Python scripts to accept typed passwords from the user, or attempting
to crack UNIX passwords with a dictionary.

`crypt(word, salt)'
     WORD will usually be a user's password as typed at a prompt or in
     a graphical interface.  SALT is usually a random two-character
     string which will be used to perturb the DES algorithm in one of
     4096 ways.  The characters in SALT must be in the set
     "[./a-zA-Z0-9]".  Returns the hashed password as a string, which
     will be composed of characters from the same alphabet as the salt
     (the first two characters represent the salt itself).

A simple example illustrating typical use:

     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


automatically generated by info2www version 1.2.2.9