1:mod:`getpass` --- Portable password input
2==========================================
3
4.. module:: getpass
5   :synopsis: Portable reading of passwords and retrieval of the userid.
6
7.. moduleauthor:: Piers Lauder <[email protected]>
8.. sectionauthor:: Fred L. Drake, Jr. <[email protected]>
9.. Windows (& Mac?) support by Guido van Rossum.
10
11**Source code:** :source:`Lib/getpass.py`
12
13--------------
14
15.. include:: ../includes/wasm-notavail.rst
16
17The :mod:`getpass` module provides two functions:
18
19.. function:: getpass(prompt='Password: ', stream=None)
20
21   Prompt the user for a password without echoing.  The user is prompted using
22   the string *prompt*, which defaults to ``'Password: '``.  On Unix, the
23   prompt is written to the file-like object *stream* using the replace error
24   handler if needed.  *stream* defaults to the controlling terminal
25   (:file:`/dev/tty`) or if that is unavailable to ``sys.stderr`` (this
26   argument is ignored on Windows).
27
28   If echo free input is unavailable getpass() falls back to printing
29   a warning message to *stream* and reading from ``sys.stdin`` and
30   issuing a :exc:`GetPassWarning`.
31
32   .. note::
33      If you call getpass from within IDLE, the input may be done in the
34      terminal you launched IDLE from rather than the idle window itself.
35
36.. exception:: GetPassWarning
37
38   A :exc:`UserWarning` subclass issued when password input may be echoed.
39
40
41.. function:: getuser()
42
43   Return the "login name" of the user.
44
45   This function checks the environment variables :envvar:`LOGNAME`,
46   :envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and
47   returns the value of the first one which is set to a non-empty string.  If
48   none are set, the login name from the password database is returned on
49   systems which support the :mod:`pwd` module, otherwise, an exception is
50   raised.
51
52   In general, this function should be preferred over :func:`os.getlogin()`.
53