pwd --- 密码数据库¶
此模块可以访问 Unix 用户账户名及密码数据库,在所有 Unix 版本上均可使用。
Availability: Unix, not Emscripten, not WASI.
密码数据库中的条目以元组对象返回,属性对应 passwd 中的结构(属性如下所示,可参考 <pwd.h>):
索引  | 
属性  | 
含意  | 
|---|---|---|
0  | 
  | 
登录名  | 
1  | 
  | 
密码,可能已经加密  | 
2  | 
  | 
用户 ID 数值  | 
3  | 
  | 
组 ID 数值  | 
4  | 
  | 
用户名或备注  | 
5  | 
  | 
用户主目录  | 
6  | 
  | 
用户的命令解释器  | 
其中 uid 和 gid 是整数,其他是字符串,如果找不到对应的项目,抛出 KeyError 异常。
备注
In traditional Unix the field 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.  On those unices the
pw_passwd field only contains an asterisk ('*') or the  letter 'x'
where the encrypted password is stored in a file /etc/shadow which is
not world readable.  Whether the pw_passwd field contains anything useful is
system-dependent.  If available, the spwd module should be used where
access to the encrypted password is required.
本模块定义如下内容:
- pwd.getpwuid(uid)¶
 给定用户的数值 ID,返回密码数据库的对应项目。
- pwd.getpwnam(name)¶
 给定用户名,返回密码数据库的对应项目。
- pwd.getpwall()¶
 返回密码数据库中所有项目的列表,顺序不是固定的。