Comparison

plugins/mod_auth_internal_hashed.lua @ 3207:b350d9753804

mod_auth_internal_hashed: Store stored_key and server_key when setting a password.
author Tobias Markmann <tm@ayena.de>
date Tue, 08 Jun 2010 14:54:47 +0200
parent 3205:2dcd826bbbc6
child 3208:4b660bf61048
comparison
equal deleted inserted replaced
3206:ff1d3f751da1 3207:b350d9753804
51 51
52 if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then 52 if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then
53 return nil, "Auth failed. Stored salt and iteration count information is not complete."; 53 return nil, "Auth failed. Stored salt and iteration count information is not complete.";
54 end 54 end
55 55
56 if credentials.saltedPasswordSHA1
57
56 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count); 58 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count);
57 local stored_key_hex = stored_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end); 59 local stored_key_hex = stored_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
58 local server_key_hex = server_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end); 60 local server_key_hex = server_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
59 61
60 if valid and stored_key_hex == credentials.stored_key and server_key_hex == credentials.server_key_hex then 62 if valid and stored_key_hex == credentials.stored_key and server_key_hex == credentials.server_key_hex then
73 end 75 end
74 76
75 if account.salt == nil then 77 if account.salt == nil then
76 account.salt = generate_uuid(); 78 account.salt = generate_uuid();
77 end 79 end
78 80
79 local valid, binpass = saltedPasswordSHA1(password, account.salt, account.iteration_count); 81 local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count);
80 local hexpass = binpass:gsub(".", function (c) return ("%02x"):format(c:byte()); end); 82 local stored_key_hex = stored_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
81 account.hashpass = hexpass; 83 local server_key_hex = server_key:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
84
85 account.stored_key = stored_key_hex
86 account.server_key = server_key_hex
82 87
83 account.password = nil; 88 account.password = nil;
84 return datamanager.store(username, host, "accounts", account); 89 return datamanager.store(username, host, "accounts", account);
85 end 90 end
86 return nil, "Account not available."; 91 return nil, "Account not available.";