Software /
code /
prosody-modules
Comparison
mod_auth_sql/mod_auth_sql.lua @ 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 |
parent | 366:c2554fee5c21 |
child | 371:c416db434e5b |
comparison
equal
deleted
inserted
replaced
366:c2554fee5c21 | 367:a6dee73a11e7 |
---|---|
77 local provider = { name = "sql" }; | 77 local provider = { name = "sql" }; |
78 log("debug", "initializing default authentication provider for host '%s'", host); | 78 log("debug", "initializing default authentication provider for host '%s'", host); |
79 | 79 |
80 function provider.test_password(username, password) | 80 function provider.test_password(username, password) |
81 log("debug", "test password '%s' for user %s at host %s", password, username, module.host); | 81 log("debug", "test password '%s' for user %s at host %s", password, username, module.host); |
82 return nil, "Password based auth not supported."; | 82 |
83 local stmt, err = getsql("SELECT `username` FROM `authreg` WHERE `username`=? AND `password`=? AND `realm`=?", | |
84 username, password, module.host); | |
85 | |
86 if stmt ~= nil then | |
87 if #stmt:rows(true) > 0 then | |
88 return true; | |
89 end | |
90 else | |
91 log("error", "QUERY ERROR: %s %s", err, debug.traceback()); | |
92 return nil, err; | |
93 end | |
94 | |
95 return false; | |
83 end | 96 end |
84 | 97 |
85 function provider.get_password(username) | 98 function provider.get_password(username) |
86 log("debug", "get_password for username '%s' at host '%s'", username, module.host); | 99 log("debug", "get_password for username '%s' at host '%s'", username, module.host); |
87 | 100 |
100 | 113 |
101 return password; | 114 return password; |
102 end | 115 end |
103 | 116 |
104 function provider.set_password(username, password) | 117 function provider.set_password(username, password) |
105 return nil, "Password based auth not supported."; | 118 return nil, "Setting password is not supported."; |
106 end | 119 end |
107 | 120 |
108 function provider.user_exists(username) | 121 function provider.user_exists(username) |
109 return nil, "User exist check not supported."; | 122 log("debug", "test user %s existence at host %s", username, module.host); |
123 | |
124 local stmt, err = getsql("SELECT `username` FROM `authreg` WHERE `username`=? AND `realm`=?", | |
125 username, module.host); | |
126 | |
127 if stmt ~= nil then | |
128 if #stmt:rows(true) > 0 then | |
129 return true; | |
130 end | |
131 else | |
132 log("error", "QUERY ERROR: %s %s", err, debug.traceback()); | |
133 return nil, err; | |
134 end | |
135 | |
136 return false; | |
110 end | 137 end |
111 | 138 |
112 function provider.create_user(username, password) | 139 function provider.create_user(username, password) |
113 return nil, "Account creation/modification not supported."; | 140 return nil, "Account creation/modification not supported."; |
114 end | 141 end |