Commit 5a5877ad authored by Brett Wilkins's avatar Brett Wilkins

MaharaAuthPlugin: Adding authentication function

parent 5e69ac3e
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* you can transparently create internal wiki accounts the first time * you can transparently create internal wiki accounts the first time
* someone logs in who can be authenticated externally. * someone logs in who can be authenticated externally.
*/ */
class MaharaAuth extends AuthPlugin { class MaharaAuthPlugin extends AuthPlugin {
/** /**
* Check whether there exists a user account with the given name. * Check whether there exists a user account with the given name.
* The name will be normalized to MediaWiki's requirements, so * The name will be normalized to MediaWiki's requirements, so
...@@ -57,7 +57,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -57,7 +57,7 @@ class MaharaAuth extends AuthPlugin {
public function userExists( $username ) { public function userExists( $username ) {
$db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname); $db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname);
$sql = "SELECT username* FROM ".$this->prefix."usr where username = '".$username."';"; $sql = "SELECT username FROM ".$this->prefix."usr where username = '".$username."';";
$res = $db->query($sql); $res = $db->query($sql);
$val = $db->fetchRow($res); $val = $db->fetchRow($res);
$db->close(); $db->close();
...@@ -78,7 +78,17 @@ class MaharaAuth extends AuthPlugin { ...@@ -78,7 +78,17 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function authenticate( $username, $password ) { public function authenticate( $username, $password ) {
# Override this! $db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname);
$sql = "SELECT username, password, salt FROM ".$this->prefix."usr where username = '".$username"';"
$res = $db->query($sql);
$val = $db->fetchRow($res);
$db->close();
if (!empty($val) && $val > 0) {
$passcheck = sha1($val->salt . $password);
if ($passcheck == $val->password) {
return true;
}
}
return false; return false;
} }
...@@ -142,7 +152,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -142,7 +152,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function autoCreate() { public function autoCreate() {
return false; return true;
} }
/** /**
...@@ -151,7 +161,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -151,7 +161,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function allowPasswordChange() { public function allowPasswordChange() {
return true; return false;
} }
/** /**
...@@ -167,7 +177,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -167,7 +177,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function setPassword( $user, $password ) { public function setPassword( $user, $password ) {
return true; return false;
} }
/** /**
...@@ -178,7 +188,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -178,7 +188,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function updateExternalDB( $user ) { public function updateExternalDB( $user ) {
return true; return false;
} }
/** /**
...@@ -201,7 +211,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -201,7 +211,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function addUser( $user, $password, $email='', $realname='' ) { public function addUser( $user, $password, $email='', $realname='' ) {
return true; return false;
} }
...@@ -214,7 +224,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -214,7 +224,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function strict() { public function strict() {
return false; return true;
} }
/** /**
...@@ -225,7 +235,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -225,7 +235,7 @@ class MaharaAuth extends AuthPlugin {
* @return bool * @return bool
*/ */
public function strictUserAuth( $username ) { public function strictUserAuth( $username ) {
return false; return true;
} }
/** /**
...@@ -262,6 +272,7 @@ class MaharaAuth extends AuthPlugin { ...@@ -262,6 +272,7 @@ class MaharaAuth extends AuthPlugin {
} }
} }
/*
class AuthPluginUser { class AuthPluginUser {
function __construct( $user ) { function __construct( $user ) {
# Override this! # Override this!
...@@ -286,4 +297,4 @@ class AuthPluginUser { ...@@ -286,4 +297,4 @@ class AuthPluginUser {
# Override this! # Override this!
return true; return true;
} }
} }*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment