blob: 20d9bb2ad0cd1492a25914dac98484608bc43cd3 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{crypt} ---
Fred Drake38e5d272000-04-03 20:13:55 +00002 Function to check \UNIX{} passwords}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{crypt}
Fred Drakea54a8871999-03-02 17:03:42 +00005 \platform{Unix}
Fred Drake38e5d272000-04-03 20:13:55 +00006\modulesynopsis{The \cfunction{crypt()} function used to check
Fred Drakec116b822001-05-09 15:50:17 +00007 \UNIX\ passwords.}
Fred Drakef6863c11999-03-02 16:37:17 +00008\moduleauthor{Steven D. Majewski}{sdm7g@virginia.edu}
9\sectionauthor{Steven D. Majewski}{sdm7g@virginia.edu}
Fred Drake38e5d272000-04-03 20:13:55 +000010\sectionauthor{Peter Funk}{pf@artcom-gmbh.de}
Fred Drakeb91e9341998-07-23 17:59:49 +000011
Guido van Rossum5c6e3731996-04-10 16:18:20 +000012
Fred Drake38e5d272000-04-03 20:13:55 +000013This module implements an interface to the
14\manpage{crypt}{3}\index{crypt(3)} routine, which is a one-way hash
15function based upon a modified DES\indexii{cipher}{DES} algorithm; see
16the \UNIX{} man page for further details. Possible uses include
Guido van Rossum5c6e3731996-04-10 16:18:20 +000017allowing Python scripts to accept typed passwords from the user, or
Fred Drakef0867311997-12-29 17:31:22 +000018attempting to crack \UNIX{} passwords with a dictionary.
Guido van Rossum5c6e3731996-04-10 16:18:20 +000019
Fred Drakecce10901998-03-17 06:33:25 +000020\begin{funcdesc}{crypt}{word, salt}
Fred Drake38e5d272000-04-03 20:13:55 +000021 \var{word} will usually be a user's password as typed at a prompt or
22 in a graphical interface. \var{salt} is usually a random
23 two-character string which will be used to perturb the DES algorithm
24 in one of 4096 ways. The characters in \var{salt} must be in the
25 set \regexp{[./a-zA-Z0-9]}. Returns the hashed password as a
26 string, which will be composed of characters from the same alphabet
27 as the salt (the first two characters represent the salt itself).
Guido van Rossum5c6e3731996-04-10 16:18:20 +000028\end{funcdesc}
29
Fred Drake38e5d272000-04-03 20:13:55 +000030
31A simple example illustrating typical use:
32
33\begin{verbatim}
34import crypt, getpass, pwd
35
36def login():
37 username = raw_input('Python login:')
38 cryptedpasswd = pwd.getpwnam(username)[1]
39 if cryptedpasswd:
40 if cryptedpasswd == 'x' or cryptedpasswd == '*':
41 raise "Sorry, currently no support for shadow passwords"
42 cleartext = getpass.getpass()
43 return crypt.crypt(cleartext, cryptedpasswd[:2]) == cryptedpasswd
44 else:
45 return 1
46\end{verbatim}