Guest User

Untitled

a guest
Jun 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. class_auth.php
  2.  
  3. class Login {
  4.     function __construct() {
  5.         if (isset($_POST['user']) and isset($_POST['pass'])) {
  6.  
  7.             //method for 1 xml file for all users
  8.             if (file_exists('data' . DIRECTORY_SEPARATOR . 'users_hktlaetaetl.xml')) {
  9.                 //Open xml
  10.                 $xml = @simplexml_load_file('data' . DIRECTORY_SEPARATOR . 'users_hktlaetaetl.xml');
  11.                 //Loop on xml file and find the username $_POST['user']
  12.                 $good_user = 0;
  13.                 $good_pass = 0;
  14.                 $name = '';
  15.                 $level = 'user';
  16.  
  17.                 foreach ($xml->children() as $user) {
  18.                     foreach ($user->attributes() as $attrib => $value) {
  19.                         if ($attrib == 'login') {
  20.                             if ($value == $_POST['user']) {
  21.                                 $good_user = 1;
  22.                             }
  23.                         }
  24.                         if ($attrib == 'pass') {
  25.                             if ($value == md5('Gg%gzµ1ß«o' . $_POST['pass'])) {
  26.                                 $good_pass = 1;
  27.                             }
  28.                         }
  29.                         if ($attrib == 'name') {
  30.                             $name = $value;
  31.                         }
  32.                         if ($attrib == 'level') {
  33.                             $level = $value;
  34.                         }
  35.                     }
  36.                     if (($good_user == 1) and ($good_pass == 1)) {
  37.                         $good_name  = $name;
  38.                         $good_level = $level;
  39.                         $connected  = 1;
  40.                     }
  41.                 }
  42.                 if ($connected == 1) {
  43.                     $_SESSION['user']->name = $good_name;
  44.                     $_SESSION['user']->level = $good_level;
  45.                     echo 'connected. redirect to homepage in 2 seconds or <a href="./index.php">click here</a>';
  46.                     echo '<script type="text/javascript">
  47.                    function redirect(){ window.location = "index.php"; }
  48.                    setTimeout(\'redirect()\', 2000);
  49.                    </script>';
  50.                 }
  51.                 if ($good_user == 0) {
  52.                     echo 'user doesn\'t exist. <button onclick="javascript:back();">go back</button>';
  53.                 } else {
  54.                     if ($good_pass == 0) {
  55.                         echo 'wrong password.<button onclick="javascript:back();">go back</button>';
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.         else {
  61.             header('Location: index.php');
  62.         }
  63.     }
  64. }
Add Comment
Please, Sign In to add comment