Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @version $Id: myauth.php 7180 2007-04-23 16:51:53Z jinx $
- * @package Joomla.Tutorials
- * @subpackage Plugins
- * @license GNU/GPL
- */
- // Check to ensure this file is included in Joomla!
- defined('_JEXEC') or die();
- /**
- * Example Authentication Plugin. Based on the example.php plugin in the Joomla! Core installation
- *
- * @package Joomla.Tutorials
- * @subpackage Plugins
- * @license GNU/GPL
- */
- class plgAuthenticationDeauth extends JPlugin
- {
- /**
- * This method should handle any authentication and report back to the subject
- * This example uses simple authentication - it checks if the password is the reverse
- * of the username (and the user exists in the database).
- *
- * @access public
- * @param array $credentials Array holding the user credentials ('username' and 'password')
- * @param array $options Array of extra options
- * @param object $response Authentication response object
- * @return boolean
- * @since 1.5
- */
- function onUserAuthenticate( $credentials, $options, &$response )
- {
- $username = $credentials['username'];
- $dbservername = "";
- $dbusername = "";
- $dbpassword = "";
- $dbname = "";
- // Create connection
- $conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
- if ($conn->connect_error) {
- $response->status = STATUS_FAILURE;
- $response->error_message = "Connection Error";
- }
- $sql = "SELECT password FROM dep WHERE username = '$username'";
- $result = $conn->query($sql);
- if (!$result) {
- $response->status = STATUS_FAILURE;
- $response->error_message = "User does not exist";
- }
- while ($row = $result->fetch_assoc()) {
- $password = $row["password"];
- echo $password;
- }
- /**
- * To authenticate, the username must exist in the database, and the password should be equal
- * to the reverse of the username (so user joeblow would have password wolbeoj)
- */
- $password2 = md5($credentials['password']);
- echo $password2;
- if($result && ($password2 == $password ))
- {
- $email = JUser::getInstance($result); // Bring this in line with the rest of the system
- $response->email = $email->email;
- $response->status = JAuthentication::STATUS_SUCCESS;
- }
- else
- {
- $response->status = JAuthentication::STATUS_FAILURE;
- $response->error_message = 'Invalid username and password';
- }
- $conn->close();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement