pwd
— The password database密码数据库¶
This module provides access to the Unix user account and password database. 此模块提供对Unix用户帐户和密码数据库的访问。It is available on all Unix versions.它在所有Unix版本上都可用。
Password database entries are reported as a tuple-like object, whose attributes correspond to the members of the 密码数据库条目报告为类似元组的对象,其属性对应于passwd
structure (Attribute field below, see <pwd.h>
):passwd
结构的成员(下面的属性字段,请参阅<pwd.h>
):
Index |
Attribute |
Meaning |
---|---|---|
0 |
|
Login name |
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
The uid and gid items are integers, all others are strings. uid和gid项是整数,其他项都是字符串。如果找不到要求的条目,则引发KeyError
is raised if the entry asked for cannot be found.KeyError
。
Note
In traditional Unix the field 在传统的Unix中,字段pw_passwd
usually contains a password encrypted with a DES derived algorithm (see module crypt
). However most modern unices use a so-called shadow password system. pw_passwd
通常包含一个用DES派生算法加密的密码(见模块crypt
)。然而,大多数现代unices都使用所谓的影子密码系统。On those unices the pw_passwd field only contains an asterisk (在这些unices上,pw_passwd字段只包含星号('*'
) or the letter 'x'
where the encrypted password is stored in a file /etc/shadow
which is not world readable. '*'
)或字母'x'
,其中加密密码存储在一个不可读的文件/etc/shadow中。Whether the pw_passwd field contains anything useful is system-dependent. pw_passwd字段是否包含有用的内容取决于系统。If available, the 如果可用,应在需要访问加密密码的地方使用spwd
module should be used where access to the encrypted password is required.spwd
模块。
It defines the following items:它定义了以下项目:
-
pwd.
getpwuid
(uid)¶ Return the password database entry for the given numeric user ID.返回给定数字用户ID的密码数据库条目。
-
pwd.
getpwnam
(name)¶ Return the password database entry for the given user name.返回给定用户名的密码数据库条目。
-
pwd.
getpwall
()¶ Return a list of all available password database entries, in arbitrary order.按任意顺序返回所有可用密码数据库条目的列表。