示例#1
0
def get_password(text1 = None, text2 = None, getfromstdin=False,
                 needrepeat=True):
    if getfromstdin:
        try:
            passwd = ''
            while not passwd:
                passwd = sys.stdin.readline()
                if not passwd:
                    return None
                passwd = passwd.rstrip('\n')
            return passwd
        except:
            return None
    if not text1:
        text1 = _('Password: '******'Repeat: ')
    try:
        pass1 = 'password'
        pass2 = 'repeat'
        while pass1 != pass2:
            pass1 = getpass.getpass(text1)
            if not needrepeat:
                return pass1
            pass2 = getpass.getpass(text2)
            if pass1 != pass2:
                print _('Passwords do not match')
    except KeyboardInterrupt:
        return None
    passwd = pass1 if (pass1 and pass1 == pass2) else ''
    return passwd
示例#2
0
def set_password(s, req, size):
    password = getpass.getpass(_('Password: '******'%s,%s' %(req,password)
    s.send(msg)
    resp = s.recv(size)
    if resp.startswith('Error'):
        _print (resp)
    return password
示例#3
0
        def askPassword(self, message, twice=False):
            from calculate.lib.utils.common import getpass

            if os.readlink("/proc/self/fd/0") == "/dev/console":
                os.system("chvt 1 &>/dev/null")
            text1 = "%s:" % message
            if not twice:
                return getpass.getpass(text1)
            if twice:
                text2 = _("Repeat: ")
                pass1 = "password"
                pass2 = "repeat"
            try:
                while pass1 != pass2:
                    pass1 = getpass.getpass(text1)
                    pass2 = getpass.getpass(text2)
                    if pass1 != pass2:
                        print _("Passwords do not match")
            except KeyboardInterrupt:
                return None
            passwd = pass1 if (pass1 and pass1 == pass2) else None
            return passwd