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