• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.. availability:: Unix, not WASI, not iOS.
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   In traditional Unix the field ``pw_passwd`` usually contains a password
43   encrypted with a DES derived algorithm.  However most
44   modern unices  use a so-called *shadow password* system.  On those unices the
45   *pw_passwd* field only contains an asterisk (``'*'``) or the  letter ``'x'``
46   where the encrypted password is stored in a file :file:`/etc/shadow` which is
47   not world readable.  Whether the *pw_passwd* field contains anything useful is
48   system-dependent.
49
50It defines the following items:
51
52
53.. function:: getpwuid(uid)
54
55   Return the password database entry for the given numeric user ID.
56
57
58.. function:: getpwnam(name)
59
60   Return the password database entry for the given user name.
61
62
63.. function:: getpwall()
64
65   Return a list of all available password database entries, in arbitrary order.
66
67
68.. seealso::
69
70   Module :mod:`grp`
71      An interface to the group database, similar to this.
72