getpass --- 可搬性のあるパスワード入力機構

ソースコード: Lib/getpass.py


Availability: not WASI.

This module does not work or is not available on WebAssembly. See WebAssemblyプラットフォーム for more information.

getpass モジュールは二つの関数を提供します:

getpass.getpass(prompt='Password: ', stream=None)

エコーなしでユーザーにパスワードを入力させるプロンプト。ユーザーは prompt の文字列をプロンプトに使え、デフォルトは 'Password: ' です。 Unixではプロンプトはファイルに似たオブジェクト stream へ、必要なら置き換えられたエラーハンドラを使って出力されます。 stream のデフォルトは、制御端末(/dev/tty)か、それが利用できない場合は sys.stderr です (この引数は Windowsでは無視されます)。

もしエコーなしで入力が利用できない場合は、 getpass()stream に警告メッセージを出力し、 sys.stdin から読み込み、 GetPassWarning 警告を発生させます。

注釈

IDLE から getpass を呼び出した場合、入力はIDLEのウィンドウではなく、IDLE を起動したターミナルから行われます。

exception getpass.GetPassWarning

UserWarning のサブクラスで、入力がエコーされてしまった場合に発生します。

getpass.getuser()

ユーザーの "ログイン名"を返します。

This function checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an OSError is raised.

一般的に、この関数は os.getlogin() よりも優先されるべきです。

バージョン 3.13 で変更: Previously, various exceptions beyond just OSError were raised.