blob: faf0f46bed34b9971e6bb791a61994ea6e049a59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<span id="getpass-portable-password-input"></span><h1>getpass — Portable password input</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/getpass.py">Lib/getpass.py</a></p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p> <p>This module does not work or is not available on WebAssembly platforms <code>wasm32-emscripten</code> and <code>wasm32-wasi</code>. See <a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p> </div> <p>The <a class="reference internal" href="#module-getpass" title="getpass: Portable reading of passwords and retrieval of the userid."><code>getpass</code></a> module provides two functions:</p> <dl class="py function"> <dt class="sig sig-object py" id="getpass.getpass">
<code>getpass.getpass(prompt='Password: ', stream=None)</code> </dt> <dd>
<p>Prompt the user for a password without echoing. The user is prompted using the string <em>prompt</em>, which defaults to <code>'Password: '</code>. On Unix, the prompt is written to the file-like object <em>stream</em> using the replace error handler if needed. <em>stream</em> defaults to the controlling terminal (<code>/dev/tty</code>) or if that is unavailable to <code>sys.stderr</code> (this argument is ignored on Windows).</p> <p>If echo free input is unavailable getpass() falls back to printing a warning message to <em>stream</em> and reading from <code>sys.stdin</code> and issuing a <a class="reference internal" href="#getpass.GetPassWarning" title="getpass.GetPassWarning"><code>GetPassWarning</code></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If you call getpass from within IDLE, the input may be done in the terminal you launched IDLE from rather than the idle window itself.</p> </div> </dd>
</dl> <dl class="py exception"> <dt class="sig sig-object py" id="getpass.GetPassWarning">
<code>exception getpass.GetPassWarning</code> </dt> <dd>
<p>A <a class="reference internal" href="exceptions#UserWarning" title="UserWarning"><code>UserWarning</code></a> subclass issued when password input may be echoed.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="getpass.getuser">
<code>getpass.getuser()</code> </dt> <dd>
<p>Return the “login name” of the user.</p> <p>This function checks the environment variables <span class="target" id="index-0"></span><code>LOGNAME</code>, <span class="target" id="index-1"></span><code>USER</code>, <code>LNAME</code> and <span class="target" id="index-2"></span><code>USERNAME</code>, 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 <a class="reference internal" href="pwd#module-pwd" title="pwd: The password database (getpwnam() and friends). (Unix)"><code>pwd</code></a> module, otherwise, an exception is raised.</p> <p>In general, this function should be preferred over <a class="reference internal" href="os#os.getlogin" title="os.getlogin"><code>os.getlogin()</code></a>.</p> </dd>
</dl> <div class="_attribution">
<p class="_attribution-p">
© 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br>
<a href="https://docs.python.org/3.12/library/getpass.html" class="_attribution-link">https://docs.python.org/3.12/library/getpass.html</a>
</p>
</div>
|