Extension talk:Auth viaMySQL

Security Risk
This login script is trivially exploited to login as any user. By simply altering the username portion of the cookie used you can change your login to any user you wish.

This is indeed a major problem. I got around this security issue by adding a hash to the cookie (Of course, change 'SECRET_HASH' to a secret passphrase): You should then update the clear_cookie and the way you set your cookie accordingly.

And then just add the following in the distribute_cookie_data function: Like this, users won't be able to switch easily to an admin user.

In your login scripts for your web page add something like:
is wrong and did not work for my mediawiki v1.14.0;

This one worked (table/row names are different):

where exactly should the login script go? This would be a nice clarification. Thanks,

Instructions Are Very Confusing

 * Now that it's talking about "MediaWiki Authentication via MySQL", but where to tell the MySQL database info, such as, hostname, database name, dababase username, password, and table name, etc.?
 * Why the MySQLActiveUser.php file needs to be in the directory just BEFORE the MediaWiki installation directory? I want to have the authentication for the MediaWiki, not for the entire Apache website.
 * "in your login/logout scritps" are especially confusing. What and where are the scripts? Why don't we just modify the LocalSettings.php to give some basic settings (including require_once, database info, etc.)?

Hope someone could make it simpler and clearer. It would be nice that it is working as this:
 * Download the Auth_viaMySQL extension to ./extensions directory
 * Modify LocalSettings.php
 * Users just need to click "Log in / create accout" at the up-right of the MW page to log in, and
 * click the "Log out" to log out.

this is how i solved my problem
Of course the code needs a bit of cleaning-up but it works

require_once('../MySQLActiveUser.php'); global $MySQLActiveUserData ; global $DBConnection ;

$username = $_POST['username']; $password = $_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $password = md5($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $command = "SELECT * FROM  WHERE username='".$username."' AND password='".$password."';"; $result = mysql_query($command) or die(mysql_error); $account = mysql_fetch_assoc($result); if ($account) { $current_mw_timecode = gmdate( 'YmdHis' ) ; $MySQLActiveUserData->set_cookie($account['username'],                                  $account['user_id'],	                           $account['password'],	                           $account['office_email'],	                           $current_mw_timecode) ; } else { echo " login fail"; }


 * What if the main web page does NOT use authentication?
 * The MySQL database for user accounts is on another machine for another website in the LAN.

= Make the above fix work = You have to put the above connection script into your existing login routine in your index.php or wherever you used to login to your MySQL database.

The following lines need to be changed to reflect the actual column header from your existing database:

$MySQLActiveUserData->set_cookie($account['username' ],                                   $account['user_id' ],                                    $account['password' ],                                    $account['user_email' ],                                    $current_mw_timecode);

= Hook Auth_viaMySQL failed to return a value =

When I use the Auth_viaMySQL.php as it is I get the following error:
 * Hook Auth_viaMySQL failed to return a value

To fix that, you have to change the following lines: function Auth_viaMySQL( &$user, &$result ) { global $MySQLActiveUserData; $MySQLActiveUserData->distribute_cookie_data ;

to: function Auth_viaMySQL( $user, &$result ) { global $MySQLActiveUserData; $MySQLActiveUserData->distribute_cookie_data ;

See the change with the variable &$user that becomes $user.