Example #1
0
    def authenticate_db(self, db, dbname, retry=True):
        """
        Returns True if we manage to auth to the given db, else False.
        """
        log_verbose("Server '%s' attempting to authenticate to db '%s'" %
                    (self.id, dbname))
        login_user = self.get_login_user(dbname)
        username = None
        password = None

        auth_success = False

        if login_user:
            username = login_user["username"]
            if "password" in login_user:
                password = login_user["password"]

        # have three attempts to authenticate
        no_tries = 0

        while not auth_success and no_tries < 3:
            if not username:
                username = read_username(dbname)
            if not password:
                password = self.lookup_password(dbname, username)
                if not password:
                    password = read_password(
                        "Enter password for user '%s\%s'" % (dbname, username))

            # if auth success then exit loop and memoize login
            try:
                auth_success = db.authenticate(username, password)
                log_verbose(
                    "Authentication attempt #%s to db '%s' result: %s" %
                    (no_tries, dbname, auth_success))
            except OperationFailure, ofe:
                if "auth fails" in str(ofe):
                    auth_success = False

            if auth_success or not retry:
                break
            else:
                log_error("Invalid login!")
                username = None
                password = None

            no_tries += 1
Example #2
0
    def authenticate_db(self, db, dbname, retry=True):
        """
        Returns True if we manage to auth to the given db, else False.
        """
        log_verbose("Server '%s' attempting to authenticate to db '%s'" % (self.id, dbname))
        login_user = self.get_login_user(dbname)
        username = None
        password = None


        auth_success = False

        if login_user:
            username = login_user["username"]
            if "password" in login_user:
                password = login_user["password"]

        # have three attempts to authenticate
        no_tries = 0

        while not auth_success and no_tries < 3:
            if not username:
                username = read_username(dbname)
            if not password:
                password = self.lookup_password(dbname, username)
                if not password:
                    password = read_password("Enter password for user '%s\%s'"%
                                             (dbname, username))

            # if auth success then exit loop and memoize login
            try:
                auth_success = db.authenticate(username, password)
                log_verbose("Authentication attempt #%s to db '%s' result: %s" % (no_tries, dbname, auth_success))
            except OperationFailure, ofe:
                if "auth fails" in str(ofe):
                    auth_success = False

            if auth_success or not retry:
                break
            else:
                log_error("Invalid login!")
                username = None
                password = None

            no_tries += 1
Example #3
0
    def authenticate_db(self, db, dbname, retry=True):
        """
        Returns True if we manage to auth to the given db, else False.
        """
        login_user = self.get_login_user(dbname)
        username = None
        password = None


        auth_success = False

        if login_user:
            username = login_user["username"]
            if "password" in login_user:
                password = login_user["password"]

        # have three attempts to authenticate
        no_tries = 0

        while not auth_success and no_tries < 3:
            if not username:
                username = read_username(dbname)
            if not password:
                password = self.lookup_password(dbname, username)
                if not password:
                    password = read_password("Enter password for user '%s\%s'"%
                                             (dbname, username))

            # if auth success then exit loop and memoize login
            auth_success = db.authenticate(username, password)
            if auth_success or not retry:
                break
            else:
                log_error("Invalid login!")
                username = None
                password = None

            no_tries += 1

        if auth_success:
            self.set_login_user(dbname, username, password)

        return auth_success