def validate_authentication(self, username, given_password, handler): self.logger.info("validate_authentication(%r, %r, %r) called" % (username, given_password, handler)) # NB: this may be tricky, for the sake of unicode names returned from the database... result = self.db.identify(username) if result is None: self.logger.warn("Warning, validate_authentication(%r) failed: no such user" % (username,)) return False actual_password, homedir, perm, msg_login, msg_quit = result if (username != "anonymous") and (eftepede_password.encode(given_password) != actual_password): self.logger.warn("Warning, validate_authentication(%r) failed: invalid password" % (username,)) return False if isinstance(homedir, str): homedir = homedir.decode("latin-1") dic = { "home": homedir, "perm": "elradfmwM", "operms": {}, "msg_login": str(msg_login), "msg_quit": str(msg_quit), } self.user_table[username] = dic self.logger.info("User %r logged in successfully..." % (username,)) return True
def add_user(self, username, password, homedir, perm="elr", msg_login="******", msg_quit="Goodbye."): if self.db.has_user(username): raise pyftpdlib.authorizers.AuthorizerError('User "%s" already exists' % (username,)) if not os.path.isdir(homedir): raise pyftpdlib.authorizers.AuthorizerError('No such directory: "%s"' % (homedir,)) homedir = os.path.realpath(homedir) self._check_permissions(username, perm) self.db.add_user(username, eftepede_password.encode(password), homedir, perm, msg_login, msg_quit)