blob: 578fb27b724bbcfb5888b8120336c179f4aedfed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<span id="pwd-the-password-database"></span><h1>pwd — The password database</h1> <p>This module provides access to the Unix user account and password database. It is available on all Unix versions.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not Emscripten, not WASI.</p> </div> <p>Password database entries are reported as a tuple-like object, whose attributes correspond to the members of the <code>passwd</code> structure (Attribute field below, see <code><pwd.h></code>):</p> <table class="docutils align-default"> <thead> <tr>
<th class="head"><p>Index</p></th> <th class="head"><p>Attribute</p></th> <th class="head"><p>Meaning</p></th> </tr> </thead> <tr>
<td><p>0</p></td> <td><p><code>pw_name</code></p></td> <td><p>Login name</p></td> </tr> <tr>
<td><p>1</p></td> <td><p><code>pw_passwd</code></p></td> <td><p>Optional encrypted password</p></td> </tr> <tr>
<td><p>2</p></td> <td><p><code>pw_uid</code></p></td> <td><p>Numerical user ID</p></td> </tr> <tr>
<td><p>3</p></td> <td><p><code>pw_gid</code></p></td> <td><p>Numerical group ID</p></td> </tr> <tr>
<td><p>4</p></td> <td><p><code>pw_gecos</code></p></td> <td><p>User name or comment field</p></td> </tr> <tr>
<td><p>5</p></td> <td><p><code>pw_dir</code></p></td> <td><p>User home directory</p></td> </tr> <tr>
<td><p>6</p></td> <td><p><code>pw_shell</code></p></td> <td><p>User command interpreter</p></td> </tr> </table> <p>The uid and gid items are integers, all others are strings. <a class="reference internal" href="exceptions#KeyError" title="KeyError"><code>KeyError</code></a> is raised if the entry asked for cannot be found.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p id="index-0">In traditional Unix the field <code>pw_passwd</code> usually contains a password encrypted with a DES derived algorithm (see module <a class="reference internal" href="crypt#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (deprecated) (Unix)"><code>crypt</code></a>). However most modern unices use a so-called <em>shadow password</em> system. On those unices the <em>pw_passwd</em> field only contains an asterisk (<code>'*'</code>) or the letter <code>'x'</code> where the encrypted password is stored in a file <code>/etc/shadow</code> which is not world readable. Whether the <em>pw_passwd</em> field contains anything useful is system-dependent. If available, the <a class="reference internal" href="spwd#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (deprecated) (Unix)"><code>spwd</code></a> module should be used where access to the encrypted password is required.</p> </div> <p>It defines the following items:</p> <dl class="py function"> <dt class="sig sig-object py" id="pwd.getpwuid">
<code>pwd.getpwuid(uid)</code> </dt> <dd>
<p>Return the password database entry for the given numeric user ID.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="pwd.getpwnam">
<code>pwd.getpwnam(name)</code> </dt> <dd>
<p>Return the password database entry for the given user name.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="pwd.getpwall">
<code>pwd.getpwall()</code> </dt> <dd>
<p>Return a list of all available password database entries, in arbitrary order.</p> </dd>
</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt>
<code>Module</code> <a class="reference internal" href="grp#module-grp" title="grp: The group database (getgrnam() and friends). (Unix)"><code>grp</code></a>
</dt>
<dd>
<p>An interface to the group database, similar to this.</p> </dd> <dt>
<code>Module</code> <a class="reference internal" href="spwd#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (deprecated) (Unix)"><code>spwd</code></a>
</dt>
<dd>
<p>An interface to the shadow password database, similar to this.</p> </dd> </dl> </div> <div class="_attribution">
<p class="_attribution-p">
© 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br>
<a href="https://docs.python.org/3.12/library/pwd.html" class="_attribution-link">https://docs.python.org/3.12/library/pwd.html</a>
</p>
</div>
|