# HG changeset patch # User Tomasz Sterna # Date 1302720113 -7200 # Node ID a6dee73a11e79fe8bb91303281febeedd6f32448 # Parent c2554fee5c21eb6db3d392331c4309f0f609c1a1 Implemented password and user existence check in mod_auth_sql diff -r c2554fee5c21 -r a6dee73a11e7 mod_auth_sql/mod_auth_sql.lua --- 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)