[Tutor] "Secure" Input?

Andrei Kulakov ak@silmarill.org
Wed, 08 Aug 2001 17:07:08 -0400


On Wed, Aug 08, 2001 at 03:53:42PM -0500, Curtis Larsen wrote:
> Hey folks -
> 
> This may have been covered before but does anyone have a suggestion as
> to how to set up a "secure" (raw?) input that doesn't echo characters
> back, or echos only stars?  I'm looking for a genteel way to ask for a
> password (of course) so... what think?
> 
> 
> Thanks!
> Curtis

GUI or console? In GUI there are various special entry box methods,
different for each GUI, I think (although I never done GUI myself).

In console, here's one way:

def set_normal_term(self):
    """Set 'normal' terminal settings"""
    if sys.version_info[0] == 2 and sys.version_info[1] == 0:
        termios.tcsetattr(self.fd, TERMIOS.TCSAFLUSH, self.old_term)
    else:
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)

def set_curses_term(self):
    """Set 'normal' terminal settings"""
    if sys.version_info[0] == 2 and sys.version_info[1] == 0:
        termios.tcsetattr(self.fd, TERMIOS.TCSAFLUSH, self.new_term)
    else:
        termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)

    self.fd = sys.stdin.fileno()
    self.new_term = termios.tcgetattr(self.fd)
    self.old_term = termios.tcgetattr(self.fd)

    if sys.version_info[0] == 2 and sys.version_info[1] == 0:
        self.new_term[3] = self.new_term[3] & ~TERMIOS.ICANON & ~TERMIOS.ECH
O
    else:
        self.new_term[3] = self.new_term[3] & ~termios.ICANON & ~termios.ECH
O

(it's different for 2.0 and newer versions, I don't know about 1.5).

self.set_curses_term()


while 1:
    c = os.read(self.fd, 1)
    print '*'
    if c == '\n':
        # check if pwd is right and break out..


 - Andrei
> 
> 
> 
> -----------------------------------------------------
> Confidentiality Notice: This e-mail transmission 
> may contain confidential or legally privileged 
> information that is intended only for the individual 
> or entity named in the e-mail address. If you are not 
> the intended recipient, you are hereby notified that 
> any disclosure, copying, distribution, or reliance 
> upon the contents of this e-mail is strictly prohibited. 
> 
> If you have received this e-mail transmission in error, 
> please reply to the sender, so that we can arrange 
> for proper delivery, and then please delete the message 
> from your inbox. Thank you.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline