Software /
code /
prosody
Comparison
plugins/mod_auth_internal_hashed.lua @ 5784:02217725454b
mod_auth_internal_hashed: Log calls to provider methods and be consistent with mod_auth_internal_plain
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 10 Aug 2013 20:19:40 +0200 |
parent | 5783:3a81e3b0ea4f |
child | 6019:e9147a16059d |
comparison
equal
deleted
inserted
replaced
5783:3a81e3b0ea4f | 5784:02217725454b |
---|---|
11 local usermanager = require "core.usermanager"; | 11 local usermanager = require "core.usermanager"; |
12 local generate_uuid = require "util.uuid".generate; | 12 local generate_uuid = require "util.uuid".generate; |
13 local new_sasl = require "util.sasl".new; | 13 local new_sasl = require "util.sasl".new; |
14 | 14 |
15 local log = module._log; | 15 local log = module._log; |
16 local host = module.host; | |
16 | 17 |
17 local accounts = module:open_store("accounts"); | 18 local accounts = module:open_store("accounts"); |
18 | 19 |
19 local to_hex; | 20 local to_hex; |
20 do | 21 do |
38 | 39 |
39 | 40 |
40 -- Default; can be set per-user | 41 -- Default; can be set per-user |
41 local iteration_count = 4096; | 42 local iteration_count = 4096; |
42 | 43 |
43 local host = module.host; | |
44 -- define auth provider | 44 -- define auth provider |
45 local provider = {}; | 45 local provider = {}; |
46 | 46 |
47 function provider.test_password(username, password) | 47 function provider.test_password(username, password) |
48 log("debug", "test password for user '%s'", username); | |
48 local credentials = accounts:get(username) or {}; | 49 local credentials = accounts:get(username) or {}; |
49 | 50 |
50 if credentials.password ~= nil and string.len(credentials.password) ~= 0 then | 51 if credentials.password ~= nil and string.len(credentials.password) ~= 0 then |
51 if credentials.password ~= password then | 52 if credentials.password ~= password then |
52 return nil, "Auth failed. Provided password is incorrect."; | 53 return nil, "Auth failed. Provided password is incorrect."; |
74 return nil, "Auth failed. Invalid username, password, or password hash information."; | 75 return nil, "Auth failed. Invalid username, password, or password hash information."; |
75 end | 76 end |
76 end | 77 end |
77 | 78 |
78 function provider.set_password(username, password) | 79 function provider.set_password(username, password) |
80 log("debug", "set_password for username '%s'", username); | |
79 local account = accounts:get(username); | 81 local account = accounts:get(username); |
80 if account then | 82 if account then |
81 account.salt = account.salt or generate_uuid(); | 83 account.salt = account.salt or generate_uuid(); |
82 account.iteration_count = account.iteration_count or iteration_count; | 84 account.iteration_count = account.iteration_count or iteration_count; |
83 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, account.salt, account.iteration_count); | 85 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, account.salt, account.iteration_count); |
94 end | 96 end |
95 | 97 |
96 function provider.user_exists(username) | 98 function provider.user_exists(username) |
97 local account = accounts:get(username); | 99 local account = accounts:get(username); |
98 if not account then | 100 if not account then |
99 log("debug", "account not found for username '%s' at host '%s'", username, host); | 101 log("debug", "account not found for username '%s'", username); |
100 return nil, "Auth failed. Invalid username"; | 102 return nil, "Auth failed. Invalid username"; |
101 end | 103 end |
102 return true; | 104 return true; |
103 end | 105 end |
104 | 106 |