Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-dl.html" /> | |
13 | <link rel="prev" href="module-grp.html" /> | |
14 | <link rel="parent" href="unix.html" /> | |
15 | <link rel="next" href="module-dl.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>8.4 crypt -- Function to check Unix passwords</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="8.3 grp " | |
25 | href="module-grp.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="8. Unix Specific Services" | |
28 | href="unix.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="8.5 dl " | |
31 | href="module-dl.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-grp.html">8.3 grp </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-dl.html">8.5 dl </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0010400000000000000000"> | |
56 | 8.4 <tt class="module">crypt</tt> -- | |
57 | Function to check <span class="Unix">Unix</span> passwords</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-crypt"></A> | |
62 | <p class="availability">Availability: <span | |
63 | class="platform">Unix</span>.</p> | |
64 | ||
65 | <P> | |
66 | This module implements an interface to the | |
67 | <span class="manpage"><i>crypt</i>(3)</span><a id='l2h-2984' xml:id='l2h-2984'></a> routine, which is a one-way hash | |
68 | function based upon a modified DES<a id='l2h-2982' xml:id='l2h-2982'></a> algorithm; see | |
69 | the <span class="Unix">Unix</span> man page for further details. Possible uses include | |
70 | allowing Python scripts to accept typed passwords from the user, or | |
71 | attempting to crack <span class="Unix">Unix</span> passwords with a dictionary. | |
72 | ||
73 | <P> | |
74 | Notice that the behavior of this module depends on the actual implementation | |
75 | of the <span class="manpage"><i>crypt</i>(3)</span><a id='l2h-2985' xml:id='l2h-2985'></a> routine in the running system. | |
76 | Therefore, any extensions available on the current implementation will also | |
77 | be available on this module. | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-2983' xml:id='l2h-2983' class="function">crypt</tt></b>(</nobr></td> | |
80 | <td><var>word, salt</var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | <var>word</var> will usually be a user's password as typed at a prompt or | |
83 | in a graphical interface. <var>salt</var> is usually a random | |
84 | two-character string which will be used to perturb the DES algorithm | |
85 | in one of 4096 ways. The characters in <var>salt</var> must be in the | |
86 | set <tt class="regexp">[./a-zA-Z0-9]</tt>. Returns the hashed password as a | |
87 | string, which will be composed of characters from the same alphabet | |
88 | as the salt (the first two characters represent the salt itself). | |
89 | ||
90 | <P> | |
91 | Since a few <span class="manpage"><i>crypt</i>(3)</span><a id='l2h-2986' xml:id='l2h-2986'></a> extensions allow different | |
92 | values, with different sizes in the <var>salt</var>, it is recommended to use | |
93 | the full crypted password as salt when checking for a password. | |
94 | </dl> | |
95 | ||
96 | <P> | |
97 | A simple example illustrating typical use: | |
98 | ||
99 | <P> | |
100 | <div class="verbatim"><pre> | |
101 | import crypt, getpass, pwd | |
102 | ||
103 | def login(): | |
104 | username = raw_input('Python login:') | |
105 | cryptedpasswd = pwd.getpwnam(username)[1] | |
106 | if cryptedpasswd: | |
107 | if cryptedpasswd == 'x' or cryptedpasswd == '*': | |
108 | raise "Sorry, currently no support for shadow passwords" | |
109 | cleartext = getpass.getpass() | |
110 | return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd | |
111 | else: | |
112 | return 1 | |
113 | </pre></div> | |
114 | ||
115 | <DIV CLASS="navigation"> | |
116 | <div class='online-navigation'> | |
117 | <p></p><hr /> | |
118 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
119 | <tr> | |
120 | <td class='online-navigation'><a rel="prev" title="8.3 grp " | |
121 | href="module-grp.html"><img src='../icons/previous.png' | |
122 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
123 | <td class='online-navigation'><a rel="parent" title="8. Unix Specific Services" | |
124 | href="unix.html"><img src='../icons/up.png' | |
125 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
126 | <td class='online-navigation'><a rel="next" title="8.5 dl " | |
127 | href="module-dl.html"><img src='../icons/next.png' | |
128 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
129 | <td align="center" width="100%">Python Library Reference</td> | |
130 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
131 | href="contents.html"><img src='../icons/contents.png' | |
132 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
133 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
134 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
135 | <td class='online-navigation'><a rel="index" title="Index" | |
136 | href="genindex.html"><img src='../icons/index.png' | |
137 | border='0' height='32' alt='Index' width='32' /></A></td> | |
138 | </tr></table> | |
139 | <div class='online-navigation'> | |
140 | <b class="navlabel">Previous:</b> | |
141 | <a class="sectref" rel="prev" href="module-grp.html">8.3 grp </A> | |
142 | <b class="navlabel">Up:</b> | |
143 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
144 | <b class="navlabel">Next:</b> | |
145 | <a class="sectref" rel="next" href="module-dl.html">8.5 dl </A> | |
146 | </div> | |
147 | </div> | |
148 | <hr /> | |
149 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
150 | </DIV> | |
151 | <!--End of Navigation Panel--> | |
152 | <ADDRESS> | |
153 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
154 | </ADDRESS> | |
155 | </BODY> | |
156 | </HTML> |