Mercurial > prosody-modules
comparison mod_auth_joomla/mod_auth_joomla.lua @ 753:9d5731af2c27
Merge with Oliver Gerlich
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 27 Jul 2012 14:29:59 +0100 |
parents | 97f6d7c4aaed |
children | 881ec9919144 |
comparison
equal
deleted
inserted
replaced
752:9bbd99f2057a | 753:9d5731af2c27 |
---|---|
10 local md5 = require "util.hashes".md5; | 10 local md5 = require "util.hashes".md5; |
11 local uuid_gen = require "util.uuid".generate; | 11 local uuid_gen = require "util.uuid".generate; |
12 | 12 |
13 local connection; | 13 local connection; |
14 local params = module:get_option("sql"); | 14 local params = module:get_option("sql"); |
15 local prefix = params and params.prefix or "jos_"; | |
15 | 16 |
16 local resolve_relative_path = require "core.configmanager".resolve_relative_path; | 17 local resolve_relative_path = require "core.configmanager".resolve_relative_path; |
17 | 18 |
18 local function test_connection() | 19 local function test_connection() |
19 if not connection then return nil; end | 20 if not connection then return nil; end |
77 if not stmt then return stmt, err; end | 78 if not stmt then return stmt, err; end |
78 return stmt:affected(); | 79 return stmt:affected(); |
79 end | 80 end |
80 | 81 |
81 local function get_password(username) | 82 local function get_password(username) |
82 local stmt, err = getsql("SELECT `password` FROM `jos_users` WHERE `username`=?", username); | 83 local stmt, err = getsql("SELECT `password` FROM `"..prefix.."users` WHERE `username`=?", username); |
83 if stmt then | 84 if stmt then |
84 for row in stmt:rows(true) do | 85 for row in stmt:rows(true) do |
85 return row.password; | 86 return row.password; |
86 end | 87 end |
87 end | 88 end |
88 end | 89 end |
89 | 90 |
90 | 91 |
91 local function getCryptedPassword(plaintext, salt) | 92 local function getCryptedPassword(plaintext, salt) |
92 return md5(plaintext..salt); | 93 local salted = plaintext..salt; |
94 return md5(salted, true); | |
93 end | 95 end |
94 local function joomlaCheckHash(password, hash) | 96 local function joomlaCheckHash(password, hash) |
95 local crypt, salt = hash:match("^([^:]*):(.*)$"); | 97 local crypt, salt = hash:match("^([^:]*):(.*)$"); |
96 return (crypt or hash) == getCryptedPassword(password, salt or ''); | 98 return (crypt or hash) == getCryptedPassword(password, salt or ''); |
97 end | 99 end |
116 function provider.get_password(username) | 118 function provider.get_password(username) |
117 return nil, "Getting password is not supported."; | 119 return nil, "Getting password is not supported."; |
118 end | 120 end |
119 function provider.set_password(username, password) | 121 function provider.set_password(username, password) |
120 local hash = joomlaCreateHash(password); | 122 local hash = joomlaCreateHash(password); |
121 local stmt, err = setsql("UPDATE `jos_users` SET `password`=? WHERE `username`=?", hash, username); | 123 local stmt, err = setsql("UPDATE `"..prefix.."users` SET `password`=? WHERE `username`=?", hash, username); |
122 return stmt and true, err; | 124 return stmt and true, err; |
123 end | 125 end |
124 function provider.create_user(username, password) | 126 function provider.create_user(username, password) |
125 return nil, "Account creation/modification not supported."; | 127 return nil, "Account creation/modification not supported."; |
126 end | 128 end |