comparison mod_auth_wordpress/mod_auth_wordpress.lua @ 424:22935ef37284

mod_auth_wordpress: Rename functions to match module name
author Kim Alvefur <zash@zash.se>
date Sun, 11 Sep 2011 21:59:01 +0200
parents 524dda2ecb6a
children 34eb9df9e37f
comparison
equal deleted inserted replaced
423:524dda2ecb6a 424:22935ef37284
159 local idx = math.min(iteration_count_log2 + 5, 30) + 1; 159 local idx = math.min(iteration_count_log2 + 5, 30) + 1;
160 output = output .. itoa64:sub(idx, idx); 160 output = output .. itoa64:sub(idx, idx);
161 output = output .. hashEncode64(input, 6); 161 output = output .. hashEncode64(input, 6);
162 return output; 162 return output;
163 end 163 end
164 local function phpbbCheckHash(password, hash) 164 local function wordpressCheckHash(password, hash)
165 if #hash == 32 then return hash == md5(password, true); end -- legacy PHPBB2 hash 165 if #hash == 32 then return hash == md5(password, true); end
166 return #hash == 34 and hashCryptPrivate(password, hash) == hash; 166 return #hash == 34 and hashCryptPrivate(password, hash) == hash;
167 end 167 end
168 local function phpbbCreateHash(password) 168 local function wordpressCreateHash(password)
169 local random = uuid_gen():sub(-6); 169 local random = uuid_gen():sub(-6);
170 local salt = hashGensaltPrivate(random); 170 local salt = hashGensaltPrivate(random);
171 local hash = hashCryptPrivate(password, salt); 171 local hash = hashCryptPrivate(password, salt);
172 if #hash == 34 then return hash; end 172 if #hash == 34 then return hash; end
173 return md5(password, true); 173 return md5(password, true);
176 176
177 provider = { name = "wordpress" }; 177 provider = { name = "wordpress" };
178 178
179 function provider.test_password(username, password) 179 function provider.test_password(username, password)
180 local hash = get_password(username); 180 local hash = get_password(username);
181 return hash and phpbbCheckHash(password, hash); 181 return hash and wordpressCheckHash(password, hash);
182 end 182 end
183 function provider.user_exists(username) 183 function provider.user_exists(username)
184 module:log("debug", "test user %s existence", username); 184 module:log("debug", "test user %s existence", username);
185 return get_password(username) and true; 185 return get_password(username) and true;
186 end 186 end
187 187
188 function provider.get_password(username) 188 function provider.get_password(username)
189 return nil, "Getting password is not supported."; 189 return nil, "Getting password is not supported.";
190 end 190 end
191 function provider.set_password(username, password) 191 function provider.set_password(username, password)
192 local hash = phpbbCreateHash(password); 192 local hash = wordpressCreateHash(password);
193 local stmt, err = setsql("UPDATE `wp_users` SET `user_pass`=? WHERE `user_login`=?", hash, username); 193 local stmt, err = setsql("UPDATE `wp_users` SET `user_pass`=? WHERE `user_login`=?", hash, username);
194 return stmt and true, err; 194 return stmt and true, err;
195 end 195 end
196 function provider.create_user(username, password) 196 function provider.create_user(username, password)
197 return nil, "Account creation/modification not supported."; 197 return nil, "Account creation/modification not supported.";