Advertisement
Telazorn

deauth.php

Jun 22nd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @version    $Id: myauth.php 7180 2007-04-23 16:51:53Z jinx $
  4.  * @package    Joomla.Tutorials
  5.  * @subpackage Plugins
  6.  * @license    GNU/GPL
  7.  */
  8.  
  9. // Check to ensure this file is included in Joomla!
  10. defined('_JEXEC') or die();
  11.  
  12. /**
  13.  * Example Authentication Plugin.  Based on the example.php plugin in the Joomla! Core installation
  14.  *
  15.  * @package    Joomla.Tutorials
  16.  * @subpackage Plugins
  17.  * @license    GNU/GPL
  18.  */
  19. class plgAuthenticationDeauth extends JPlugin
  20. {
  21.     /**
  22.      * This method should handle any authentication and report back to the subject
  23.      * This example uses simple authentication - it checks if the password is the reverse
  24.      * of the username (and the user exists in the database).
  25.      *
  26.      * @access    public
  27.      * @param     array     $credentials    Array holding the user credentials ('username' and 'password')
  28.      * @param     array     $options        Array of extra options
  29.      * @param     object    $response       Authentication response object
  30.      * @return    boolean
  31.      * @since 1.5
  32.      */
  33.     function onUserAuthenticate( $credentials, $options, &$response )
  34.     {
  35.          $username = $credentials['username'];
  36.          $dbservername = "";
  37.          $dbusername = "";
  38.          $dbpassword = "";
  39.          $dbname = "";
  40.  
  41.           // Create connection
  42.           $conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
  43.            if ($conn->connect_error) {
  44.               $response->status = STATUS_FAILURE;
  45.               $response->error_message = "Connection Error";
  46.            }
  47.            $sql = "SELECT password FROM dep WHERE username = '$username'";
  48.            $result = $conn->query($sql);
  49.        
  50.         if (!$result) {
  51.             $response->status = STATUS_FAILURE;
  52.             $response->error_message = "User does not exist";
  53.         }
  54.        
  55.         while ($row = $result->fetch_assoc()) {
  56.             $password = $row["password"];
  57.             echo $password;
  58.         }
  59.         /**
  60.          * To authenticate, the username must exist in the database, and the password should be equal
  61.          * to the reverse of the username (so user joeblow would have password wolbeoj)
  62.          */
  63.          $password2 = md5($credentials['password']);
  64.          echo $password2;
  65.         if($result && ($password2 == $password ))
  66.         {
  67.         $email = JUser::getInstance($result); // Bring this in line with the rest of the system
  68.         $response->email = $email->email;
  69.         $response->status = JAuthentication::STATUS_SUCCESS;
  70.  
  71.         }
  72.         else
  73.         {
  74.             $response->status = JAuthentication::STATUS_FAILURE;
  75.             $response->error_message = 'Invalid username and password';
  76.         }
  77.         $conn->close();
  78.     }
  79. }
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement