Comparison

util/sasl/plain.lua @ 2994:b8448e181487

util.sasl.plain: Adding plain_hashed authentication backend support.
author Tobias Markmann <tm@ayena.de>
date Sun, 28 Feb 2010 22:50:25 +0100
parent 2991:0fa3a7c885bd
child 2996:b0515ed4d9d7
comparison
equal deleted inserted replaced
2993:06d06fdd190b 2994:b8448e181487
30 30
31 plain-test: 31 plain-test:
32 function(username, realm, password) 32 function(username, realm, password)
33 return true or false, state; 33 return true or false, state;
34 end 34 end
35
36 plain-hashed:
37 function(username, realm)
38 return hashed_password, hash_function, state;
39 end
35 ]] 40 ]]
36 41
37 local function plain(self, message) 42 local function plain(self, message)
38 if not message then 43 if not message then
39 return "failure", "malformed-request"; 44 return "failure", "malformed-request";
59 local correct_password; 64 local correct_password;
60 correct_password, state = self.profile.plain(authentication, self.realm); 65 correct_password, state = self.profile.plain(authentication, self.realm);
61 if correct_password == password then correct = true; else correct = false; end 66 if correct_password == password then correct = true; else correct = false; end
62 elseif self.profile.plain_test then 67 elseif self.profile.plain_test then
63 correct, state = self.profile.plain_test(authentication, self.realm, password); 68 correct, state = self.profile.plain_test(authentication, self.realm, password);
69 elseif self.profile.plain_hashed then
70 local hashed_password, hash_f;
71 hashed_password, hash_f, state = self.profile.plain_hashed(authentication, self.realm);
72 if hashed_password == hash_f(password) then correct = true; else correct = false; end
64 end 73 end
65 74
66 self.username = authentication 75 self.username = authentication
67 if not state then 76 if not state then
68 return "failure", "account-disabled"; 77 return "failure", "account-disabled";
74 return "failure", "not-authorized", "Unable to authorize you with the authentication credentials you've sent."; 83 return "failure", "not-authorized", "Unable to authorize you with the authentication credentials you've sent.";
75 end 84 end
76 end 85 end
77 86
78 function init(registerMechanism) 87 function init(registerMechanism)
79 registerMechanism("PLAIN", {"plain", "plain_test"}, plain); 88 registerMechanism("PLAIN", {"plain", "plain_test", "plain_hashed"}, plain);
80 end 89 end
81 90
82 return _M; 91 return _M;