-
- if authentication == nil or password == nil then return "failure", "malformed-request" end
-
- local password_encoding, correct_password = self.password_handler(authentication, self.realm, "PLAIN")
-
- if correct_password == nil then return "failure", "not-authorized"
- elseif correct_password == false then return "failure", "account-disabled" end
-
- local claimed_password = ""
- if password_encoding == nil then claimed_password = password
- else claimed_password = password_encoding(password) end
-
- self.username = authentication
- if claimed_password == correct_password then
- return "success"
- else
- return "failure", "not-authorized"
- end
- end
- return object
+
+ if authentication == nil or password == nil then return "failure", "malformed-request" end
+ self.username = authentication
+ local auth_success = self.credentials_handler("PLAIN", self.username, self.realm, password)
+
+ if auth_success then
+ return "success"
+ elseif auth_success == nil then
+ return "failure", "account-disabled"
+ else
+ return "failure", "not-authorized"
+ end
+ end
+ return object