getpass — 이식성 있는 암호 입력¶
소스 코드: Lib/getpass.py
The getpass module provides two functions:
- getpass.getpass(prompt='Password: ', stream=None, *, echo_char=None)¶
에코 없이 사용자에게 암호를 묻습니다. 사용자는 prompt 문자열을 사용하여 프롬프트 됩니다. 기본값은
'Password: '입니다. 유닉스에서 프롬프트는 필요하다면 replace 에러 처리기를 사용하여 파일류 객체 stream에 기록됩니다. stream는 제어 터미널(/dev/tty)이나 사용할 수 없으면sys.stderr를 기본값으로 사용합니다 (이 인자는 윈도우에서 무시됩니다).The echo_char argument controls how user input is displayed while typing. If echo_char is
None(default), input remains hidden. Otherwise, echo_char must be a single printable ASCII character and each typed character is replaced by it. For example,echo_char='*'will display asterisks instead of the actual input.If echo-free input is unavailable,
getpass()falls back to printing a warning message to stream and reading fromsys.stdinand issuing aGetPassWarning.참고
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.참고
On Unix systems, when echo_char is set, the terminal will be configured to operate in noncanonical mode. Common terminal control characters are supported:
Ctrl+A - Move cursor to beginning of line
Ctrl+E - Move cursor to end of line
Ctrl+K - Kill (delete) from cursor to end of line
Ctrl+U - Kill (delete) entire line
Ctrl+W - Erase previous word
Ctrl+V - Insert next character literally (quote)
Backspace/DEL - Delete character before cursor
These shortcuts work by reading the terminal’s configured control character mappings from termios settings.
버전 3.14에서 변경: Added the echo_char parameter for keyboard feedback.
버전 3.15에서 변경: When using non-empty echo_char on Unix, keyboard shortcuts (including cursor movement and line editing) are now properly handled using the terminal’s control character configuration.
- exception getpass.GetPassWarning¶
패스워드 입력이 에코 될 때 방출되는
UserWarning서브 클래스.
- getpass.getuser()¶
사용자의 “로그인 이름”을 반환합니다.
이 함수는 환경 변수
LOGNAME,USER,LNAME및USERNAME를 순서대로 검사하고, 비어 있지 않은 문자열로 설정된 첫 번째 값을 반환합니다. 아무것도 설정되지 않았으면,pwd모듈을 지원하는 시스템에서는 암호 데이터베이스의 로그인 이름이 반환되고, 그렇지 않으면OSError가 발생합니다.일반적으로, 이 함수는
os.getlogin()보다 선호됩니다.버전 3.13에서 변경: Previously, various exceptions beyond just
OSErrorwere raised.