def tty_entry(tty_name, prompt): # Copied from https://github.com/python/cpython/blob/3.6/Lib/getpass.py # Make tty configurable, derive defaults from None tty_name = tty_name or '/dev/tty' stream = None passwd = None with contextlib.ExitStack() as stack: try: # Always try reading and writing directly on the tty first. fd = os.open(tty_name, os.O_RDWR | os.O_NOCTTY) tty = io.FileIO(fd, 'w+') stack.enter_context(tty) input = io.TextIOWrapper(tty) stack.enter_context(input) if not stream: stream = input except OSError as e: # If that fails, see if stdin can be controlled. stack.close() try: fd = sys.stdin.fileno() except (AttributeError, ValueError): fd = None passwd = fallback_getpass(prompt, stream) input = sys.stdin if not stream: stream = sys.stderr if fd is not None: try: old = termios.tcgetattr(fd) # a copy to save new = old[:] new[3] &= ~termios.ECHO # 3 == 'lflags' tcsetattr_flags = termios.TCSAFLUSH if hasattr(termios, 'TCSASOFT'): tcsetattr_flags |= termios.TCSASOFT try: termios.tcsetattr(fd, tcsetattr_flags, new) passwd = _raw_input(prompt, stream, input=input) finally: termios.tcsetattr(fd, tcsetattr_flags, old) stream.flush() # issue7208 except termios.error: if passwd is not None: # _raw_input succeeded. The final tcsetattr failed. Reraise # noqa # instead of leaving the terminal in an unknown state. raise # We can't control the tty or stdin. Give up and use normal IO. # noqa # fallback_getpass() raises an appropriate warning. if stream is not input: # clean up unused file objects before blocking stack.close() passwd = fallback_getpass(prompt, stream) stream.write('\n') return passwd
def os_getpass(prompt, stream=None): """Prompt for password with echo off, using Windows getch().""" if sys.stdin is not sys.__stdin__: return getpass.fallback_getpass(prompt, stream) for c in prompt: msvcrt.putch(c) pw = "" while True: c = msvcrt.getch() if c == '\r' or c == '\n': break if c == '\003': raise KeyboardInterrupt if c == '\b': if pw == '': pass else: pw = pw[:-1] msvcrt.putch('\b') msvcrt.putch(" ") msvcrt.putch('\b') else: pw = pw + c msvcrt.putch("*") msvcrt.putch('\r') msvcrt.putch('\n') return pw
def __entry_to_fs(self): is_exists = False while not is_exists: login = None password = None try: login = input('Login: '******'Password: '******'Bye!') exit(0) hash_pass = hashlib.md5(password.encode('utf-8')).hexdigest() is_exists, user = self.__login(login, hash_pass) if not is_exists: self.write_out('Not valid pair login,password, please try again') current_dir = self.__set_default_directory(user) self.__session = Session(user, current_dir)
def get_password(message_text): import getpass # running under PyCharm or not if 'PYCHARM_HOSTED' in os.environ: return getpass.fallback_getpass(message_text) else: return getpass.getpass(message_text)
def update_event(self, inp=-1): self.set_output_val( 0, getpass.fallback_getpass(self.input(0), self.input(1)))