Merge 0.9->0.10
[prosody.git] / util / sasl / plain.lua
index fb20cf97d45e0424afd7c7044c5062dc37d68b73..c9ec2911797ecaacae50ac0e6f969adb062b5591 100644 (file)
@@ -13,6 +13,7 @@
 
 local s_match = string.match;
 local saslprep = require "util.encodings".stringprep.saslprep;
+local nodeprep = require "util.encodings".stringprep.nodeprep;
 local log = require "util.logger".init("sasl");
 
 module "sasl.plain"
@@ -54,6 +55,14 @@ local function plain(self, message)
                return "failure", "malformed-request", "Invalid username or password.";
        end
 
+       local _nodeprep = self.profile.nodeprep;
+       if _nodeprep ~= false then
+               authentication = (_nodeprep or nodeprep)(authentication);
+               if not authentication or authentication == "" then
+                       return "failure", "malformed-request", "Invalid username or password."
+               end
+       end
+
        local correct, state = false, false;
        if self.profile.plain then
                local correct_password;
@@ -64,15 +73,13 @@ local function plain(self, message)
        end
 
        self.username = authentication
-       if not state then
+       if state == false then
                return "failure", "account-disabled";
-       end
-
-       if correct then
-               return "success";
-       else
+       elseif state == nil or not correct then
                return "failure", "not-authorized", "Unable to authorize you with the authentication credentials you've sent.";
        end
+
+       return "success";
 end
 
 function init(registerMechanism)