error = ldap_error($ldap_link); $auth['error'] = libglue_param('login_failed'); } } } // // Here means we couldn't use the service. // So it's most likely config related. // Check the username and password? // else { $auth['error'] = libglue_param('bad_auth_cred'); } } // // This most often will mean we can't reach the server. // Perhaps it's down, or we mistyped the address. // else { $auth['error'] = libglue_param('connect_error'); } // Done with the link, give it back ldap_close($ldap_link); $auth['type'] = 'ldap'; return $auth; } /* * MySQL authentication. * returns true/false depending on whether the user was authenticated * successfully * The crypt settings below assume the php crypt() function created the passwords. * But hopson updated it to use mysql PASSWORD() instead */ function auth_mysql($username, $password) { $auth = array(); $auth['success'] = 0; // Did we get fed proper variables? if(!$username or !$password) { $auth['error'] = 'Empty username/password'; return $auth; } // // Retrieve config parameters set in config.php // $dbhost = libglue_param('mysql_host'); $dbuser = libglue_param('mysql_user'); $dbpass = libglue_param('mysql_pass'); $dbname = libglue_param('mysql_db'); $passfield = libglue_param('mysql_passcol'); $table = libglue_param('mysql_table'); $usercol = libglue_param('mysql_usercol'); $other = libglue_param('mysql_other'); $fields = libglue_param('mysql_fields'); $mysql_uidfield = libglue_param('mysql_uidfield'); $mysql_usernamefield = libglue_param('mysql_usernamefield'); if(!preg_match("/$mysql_uidfield/",$fields)) $fields .= ",$mysql_uidfield"; if(!preg_match("/$mysql_usernamefield/",$fields)) $fields .= ",$mysql_usernamefield"; if($other == '') $other = '1=1'; if ($mysql_link = @mysql_connect($dbhost,$dbuser,$dbpass)) { // // now retrieve the stored password to use as salt // for password checking // $sql = "SELECT $passfield FROM $table" . " WHERE $usercol = '$username' " . " AND $other LIMIT 1"; @mysql_select_db($dbname, $mysql_link); $result = @mysql_query($sql, $mysql_link); $row = @mysql_fetch_array($result); $password_check_sql = "PASSWORD('$password')"; $sql = "SELECT version()"; $db_results = @mysql_query($sql, $mysql_link); $version = @mysql_fetch_array($db_results); $mysql_version = substr(preg_replace("/(\d+)\.(\d+)\.(\d+).*/","$1$2$3",$version[0]),0,3); if ($mysql_version > "409" AND substr($row[0],0,1) !== "*") { $password_check_sql = "OLD_PASSWORD('$password')"; } $sql = "SELECT $fields FROM $table" . " WHERE $usercol = '$username'" . " AND $passfield = $password_check_sql" . " AND $other LIMIT 1"; $rs = @mysql_query($sql, $mysql_link); //This should only fail on a badly formed query. if(!$rs) { $auth['error'] = @mysql_error(); } // // Retrieved the right info, set auth->success and info. // if (@mysql_num_rows($rs) == 1) { // username and password are successful $row = mysql_fetch_array($rs); $sess_username = libglue_param('user_username'); $sess_id = libglue_param('user_id'); $auth[$info][$sess_username] = $row[$mysql_usernamefield]; $auth[$info][$sess_id] = $row[$mysql_uidfield]; $auth[$info] = $row; $auth['info'] = $row; $auth['success'] = 1; } // // We didn't find anything matching. No user, bad password, ? // else { $auth['error'] = libglue_param('login_failed'); } } // // Couldn't connect to database at all. // else { $auth['error'] = libglue_param('bad_auth_cred'); } $auth['type'] = 'mysql'; return $auth; } // auth_mysql function auth_sso ($username, $password) { $auth = new auth_response(); $auth->success = 0; $auth->error = "SSO Authentication failed."; return $auth; } // This is the auth_response class that will be returned during // and authentication - this allows us to set some variables // by the session for later lookup class auth_response { var $username; var $userid; var $error; var $success; var $info; } ?>