Skip to content

Instantly share code, notes, and snippets.

@Ivlyth
Created July 28, 2015 07:56
Show Gist options
  • Save Ivlyth/db88de560dd95a77426c to your computer and use it in GitHub Desktop.
Save Ivlyth/db88de560dd95a77426c to your computer and use it in GitHub Desktop.
get_passwd_from_user_with_termios

get passwd from user with termios

def getpass(prompt="Password: "):
    import termios, sys
    fd = sys.stdin.fileno()
    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    new[3] = new[3] & ~termios.ECHO          # lflags
    try:
        termios.tcsetattr(fd, termios.TCSADRAIN, new)
        passwd = raw_input(prompt)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old)
    return passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment