Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libcrypt.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 6dc36078f53e |
| children | 9582fa2e5e0d |
| rev | line source |
|---|---|
| 8918 | 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 | 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 | 8 \moduleauthor{Steven D. Majewski}{sdm7g@virginia.edu} |
| 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 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7341
diff
changeset
|
20 \begin{funcdesc}{crypt}{word, salt} |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
21 \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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 as the salt (the first two characters represent the salt itself). |
|
3509
558dce6553d9
Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 \end{funcdesc} |
|
558dce6553d9
Added lost docs for crypt module.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
12223
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
30 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
31 A simple example illustrating typical use: |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
32 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
33 \begin{verbatim} |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
34 import crypt, getpass, pwd |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
35 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
36 def login(): |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
37 username = raw_input('Python login:') |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
38 cryptedpasswd = pwd.getpwnam(username)[1] |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
39 if cryptedpasswd: |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
40 if cryptedpasswd == 'x' or cryptedpasswd == '*': |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
41 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
|
42 cleartext = getpass.getpass() |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
43 return crypt.crypt(cleartext, cryptedpasswd[:2]) == cryptedpasswd |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
44 else: |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
45 return 1 |
|
e82e82b3b9ad
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
46 \end{verbatim} |
