annotate Doc/lib/libcrypt.tex @ 37850:ebe59cd18273

Use explicit relative import for an, ehm, relative import.
author Thomas Wouters <thomas@python.org>
date Tue, 18 Apr 2006 21:41:36 +0000
parents 081b4f0e81b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
1 \section{\module{crypt} ---
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
2 Function to check \UNIX{} passwords}
10334
61224459bb09 Added \platform annotations.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
3
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
4 \declaremodule{builtin}{crypt}
10335
093fc298afd6 "\platform{UNIX}" should really be spelled "\platform{Unix}".
Fred Drake <fdrake@acm.org>
parents: 10334
diff changeset
5 \platform{Unix}
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
6 \modulesynopsis{The \cfunction{crypt()} function used to check
17724
6dc36078f53e Work around limitations of the module synopsis table generation to avoid
Fred Drake <fdrake@acm.org>
parents: 12223
diff changeset
7 \UNIX\ passwords.}
10334
61224459bb09 Added \platform annotations.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
8 \moduleauthor{Steven D. Majewski}{sdm7g@virginia.edu}
61224459bb09 Added \platform annotations.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
9 \sectionauthor{Steven D. Majewski}{sdm7g@virginia.edu}
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
10 \sectionauthor{Peter Funk}{pf@artcom-gmbh.de}
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
11
3509
558dce6553d9 Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
13 This module implements an interface to the
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
14 \manpage{crypt}{3}\index{crypt(3)} routine, which is a one-way hash
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
15 function based upon a modified DES\indexii{cipher}{DES} algorithm; see
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
16 the \UNIX{} man page for further details. Possible uses include
3509
558dce6553d9 Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 allowing Python scripts to accept typed passwords from the user, or
6959
fedbf9325190 Normalized the word "Unix" to "\UNIX{}".
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
18 attempting to crack \UNIX{} passwords with a dictionary.
3509
558dce6553d9 Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
32813
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
20 Notice that the behavior of this module depends on the actual implementation
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
21 of the \manpage{crypt}{3}\index{crypt(3)} routine in the running system.
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
22 Therefore, any extensions available on the current implementation will also
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
23 be available on this module.
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7341
diff changeset
24 \begin{funcdesc}{crypt}{word, salt}
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
25 \var{word} will usually be a user's password as typed at a prompt or
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
26 in a graphical interface. \var{salt} is usually a random
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
27 two-character string which will be used to perturb the DES algorithm
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
28 in one of 4096 ways. The characters in \var{salt} must be in the
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
29 set \regexp{[./a-zA-Z0-9]}. Returns the hashed password as a
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
30 string, which will be composed of characters from the same alphabet
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
31 as the salt (the first two characters represent the salt itself).
32813
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
32
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
33 Since a few \manpage{crypt}{3}\index{crypt(3)} extensions allow different
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
34 values, with different sizes in the \var{salt}, it is recommended to use
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
35 the full crypted password as salt when checking for a password.
3509
558dce6553d9 Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \end{funcdesc}
558dce6553d9 Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
38
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
39 A simple example illustrating typical use:
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
40
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
41 \begin{verbatim}
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
42 import crypt, getpass, pwd
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
43
37045
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
44 def raw_input(prompt):
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
45 import sys
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
46 sys.stdout.write(prompt)
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
47 sys.stdout.flush()
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
48 return sys.stdin.readline()
081b4f0e81b7 Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents: 32813
diff changeset
49
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
50 def login():
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
51 username = raw_input('Python login:')
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
52 cryptedpasswd = pwd.getpwnam(username)[1]
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
53 if cryptedpasswd:
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
54 if cryptedpasswd == 'x' or cryptedpasswd == '*':
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
55 raise "Sorry, currently no support for shadow passwords"
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
56 cleartext = getpass.getpass()
32813
9582fa2e5e0d Patch #997668: Correct explanation of salts.
Martin v. Löwis <martin@v.loewis.de>
parents: 17724
diff changeset
57 return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
12223
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
58 else:
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
59 return 1
e82e82b3b9ad Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10335
diff changeset
60 \end{verbatim}