Mercurial > prosody-modules
changeset 367:a6dee73a11e7
Implemented password and user existence check in mod_auth_sql
author | Tomasz Sterna <tomek@xiaoka.com> |
---|---|
date | Wed, 13 Apr 2011 20:41:53 +0200 |
parents | c2554fee5c21 |
children | 1f55e844efeb |
files | mod_auth_sql/mod_auth_sql.lua |
diffstat | 1 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_auth_sql/mod_auth_sql.lua Wed Apr 13 15:37:26 2011 +0200 +++ b/mod_auth_sql/mod_auth_sql.lua Wed Apr 13 20:41:53 2011 +0200 @@ -79,7 +79,20 @@ function provider.test_password(username, password) log("debug", "test password '%s' for user %s at host %s", password, username, module.host); - return nil, "Password based auth not supported."; + + local stmt, err = getsql("SELECT `username` FROM `authreg` WHERE `username`=? AND `password`=? AND `realm`=?", + username, password, module.host); + + if stmt ~= nil then + if #stmt:rows(true) > 0 then + return true; + end + else + log("error", "QUERY ERROR: %s %s", err, debug.traceback()); + return nil, err; + end + + return false; end function provider.get_password(username) @@ -102,11 +115,25 @@ end function provider.set_password(username, password) - return nil, "Password based auth not supported."; + return nil, "Setting password is not supported."; end function provider.user_exists(username) - return nil, "User exist check not supported."; + log("debug", "test user %s existence at host %s", username, module.host); + + local stmt, err = getsql("SELECT `username` FROM `authreg` WHERE `username`=? AND `realm`=?", + username, module.host); + + if stmt ~= nil then + if #stmt:rows(true) > 0 then + return true; + end + else + log("error", "QUERY ERROR: %s %s", err, debug.traceback()); + return nil, err; + end + + return false; end function provider.create_user(username, password)