Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`getpass` --- Portable password input |
| 2 | ========================================== |
| 3 | |
| 4 | .. module:: getpass |
| 5 | :synopsis: Portable reading of passwords and retrieval of the userid. |
| 6 | .. moduleauthor:: Piers Lauder <piers@cs.su.oz.au> |
| 7 | .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 8 | .. Windows (& Mac?) support by Guido van Rossum. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 9 | |
| 10 | The :mod:`getpass` module provides two functions: |
| 11 | |
| 12 | |
Georg Brandl | 036490d | 2009-05-17 13:00:36 +0000 | [diff] [blame] | 13 | .. function:: getpass(prompt='Password: ', stream=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 14 | |
Georg Brandl | e6bcc91 | 2008-05-12 18:05:20 +0000 | [diff] [blame] | 15 | Prompt the user for a password without echoing. The user is prompted using |
R David Murray | 604453c | 2014-04-14 10:28:58 -0400 | [diff] [blame] | 16 | the string *prompt*, which defaults to ``'Password: '``. On Unix, the |
| 17 | prompt is written to the file-like object *stream* using the replace error |
| 18 | handler if needed. *stream* defaults to the controlling terminal |
| 19 | (:file:`/dev/tty`) or if that is unavailable to ``sys.stderr`` (this |
| 20 | argument is ignored on Windows). |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 21 | |
| 22 | If echo free input is unavailable getpass() falls back to printing |
| 23 | a warning message to *stream* and reading from ``sys.stdin`` and |
| 24 | issuing a :exc:`GetPassWarning`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 | |
| 26 | Availability: Macintosh, Unix, Windows. |
| 27 | |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 28 | .. note:: |
| 29 | If you call getpass from within IDLE, the input may be done in the |
| 30 | terminal you launched IDLE from rather than the idle window itself. |
| 31 | |
| 32 | .. exception:: GetPassWarning |
| 33 | |
| 34 | A :exc:`UserWarning` subclass issued when password input may be echoed. |
| 35 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 36 | |
| 37 | .. function:: getuser() |
| 38 | |
| 39 | Return the "login name" of the user. Availability: Unix, Windows. |
| 40 | |
| 41 | This function checks the environment variables :envvar:`LOGNAME`, |
| 42 | :envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and returns |
| 43 | the value of the first one which is set to a non-empty string. If none are set, |
| 44 | the login name from the password database is returned on systems which support |
| 45 | the :mod:`pwd` module, otherwise, an exception is raised. |
| 46 | |