1:mod:`pwd` --- The password database
2====================================
3
4.. module:: pwd
5   :platform: Unix
6   :synopsis: The password database (getpwnam() and friends).
7
8--------------
9
10This module provides access to the Unix user account and password database.  It
11is available on all Unix versions.
12
13.. include:: ../includes/wasm-notavail.rst
14
15Password database entries are reported as a tuple-like object, whose attributes
16correspond to the members of the ``passwd`` structure (Attribute field below,
17see ``<pwd.h>``):
18
19+-------+---------------+-----------------------------+
20| Index | Attribute     | Meaning                     |
21+=======+===============+=============================+
22| 0     | ``pw_name``   | Login name                  |
23+-------+---------------+-----------------------------+
24| 1     | ``pw_passwd`` | Optional encrypted password |
25+-------+---------------+-----------------------------+
26| 2     | ``pw_uid``    | Numerical user ID           |
27+-------+---------------+-----------------------------+
28| 3     | ``pw_gid``    | Numerical group ID          |
29+-------+---------------+-----------------------------+
30| 4     | ``pw_gecos``  | User name or comment field  |
31+-------+---------------+-----------------------------+
32| 5     | ``pw_dir``    | User home directory         |
33+-------+---------------+-----------------------------+
34| 6     | ``pw_shell``  | User command interpreter    |
35+-------+---------------+-----------------------------+
36
37The uid and gid items are integers, all others are strings. :exc:`KeyError` is
38raised if the entry asked for cannot be found.
39
40.. note::
41
42   .. index:: pair: module; crypt
43
44   In traditional Unix the field ``pw_passwd`` usually contains a password
45   encrypted with a DES derived algorithm (see module :mod:`crypt`).  However most
46   modern unices  use a so-called *shadow password* system.  On those unices the
47   *pw_passwd* field only contains an asterisk (``'*'``) or the  letter ``'x'``
48   where the encrypted password is stored in a file :file:`/etc/shadow` which is
49   not world readable.  Whether the *pw_passwd* field contains anything useful is
50   system-dependent.  If available, the :mod:`spwd` module should be used where
51   access to the encrypted password is required.
52
53It defines the following items:
54
55
56.. function:: getpwuid(uid)
57
58   Return the password database entry for the given numeric user ID.
59
60
61.. function:: getpwnam(name)
62
63   Return the password database entry for the given user name.
64
65
66.. function:: getpwall()
67
68   Return a list of all available password database entries, in arbitrary order.
69
70
71.. seealso::
72
73   Module :mod:`grp`
74      An interface to the group database, similar to this.
75
76   Module :mod:`spwd`
77      An interface to the shadow password database, similar to this.
78
79