| 1 |
<?php |
<?php |
| 2 |
// $Id: sql_auth.module,v 1.13 2006/02/23 19:34:19 ber Exp $ |
// $Id: sql_auth.module,v 1.1 2006/02/23 20:07:06 ber Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 121 |
* Helper for sql_auth_auth |
* Helper for sql_auth_auth |
| 122 |
*/ |
*/ |
| 123 |
function sql_auth_query($username, $password) { |
function sql_auth_query($username, $password) { |
| 124 |
|
$salt = ''; |
| 125 |
|
if (variable_get('sql_auth_pass_salt', 0)) { |
| 126 |
|
$salt = ', '. variable_get('sql_auth_pass_col', 'pass'); |
| 127 |
|
} |
| 128 |
|
$res = db_fetch_array(_sql_auth_query("SELECT %s AS name FROM %s WHERE %s = '%s' AND %s = %s('%s'%s)", array(variable_get('sql_auth_user_col', 'name'), variable_get('sql_auth_table', 'users'), variable_get('sql_auth_user_col', 'name'), $username, variable_get('sql_auth_pass_col', 'pass'), _sql_auth_current_scheme(), $password, $salt))); |
| 129 |
|
if (!empty($res['name'])) { //we have a winner! |
| 130 |
|
return $res['name']; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
return FALSE; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
/** |
| 137 |
|
* do a query to the database using credentials defined in this module's configuration |
| 138 |
|
* |
| 139 |
|
* helper for sql_auth_query() |
| 140 |
|
*/ |
| 141 |
|
function _sql_auth_query($query, $args = null) { |
| 142 |
global $db_url, $active_db; |
global $db_url, $active_db; |
| 143 |
|
|
| 144 |
$behold_db_url = $db_url; |
$behold_db_url = $db_url; |
| 158 |
db_set_active(variable_get('sql_auth_string', 'mysql://username:password@localhost/database')); |
db_set_active(variable_get('sql_auth_string', 'mysql://username:password@localhost/database')); |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
if (variable_get('sql_auth_pass_salt', 0)) { |
$query = db_query($query, $args); |
|
$salt = ', '. variable_get('sql_auth_pass_col', 'pass'); |
|
|
} |
|
|
$res = db_fetch_array(db_query("SELECT %s AS name FROM %s WHERE %s = '%s' AND %s = %s('%s'%s)", |
|
|
variable_get('sql_auth_user_col', 'name'), |
|
|
variable_get('sql_auth_table', 'users'), |
|
|
variable_get('sql_auth_user_col', 'name'), |
|
|
$username, |
|
|
variable_get('sql_auth_pass_col', 'pass'), |
|
|
_sql_auth_current_scheme(), |
|
|
$password, |
|
|
$salt |
|
|
)); |
|
| 162 |
|
|
| 163 |
db_set_active(); //set the connection back |
db_set_active(); //set the connection back |
| 164 |
|
|
| 165 |
unset($db_url); |
unset($db_url); |
| 166 |
$db_url = $behold_db_url; |
$db_url = $behold_db_url; |
| 167 |
|
|
| 168 |
if (!empty($res['name'])) { //we have a winner! |
return $query; |
|
return $res['name']; |
|
|
} |
|
|
|
|
|
return FALSE; |
|
| 169 |
} |
} |
| 170 |
|
|
| 171 |
/** |
/** |