Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <?php
  2. if(!defined('VALID_ACL_')) exit('direct access is not allowed.');
  3.  
  4. class Authorization
  5. {
  6.    
  7.     public function check_status()
  8.         {
  9.             if(empty($_SESSION['exp_user']) || @$_SESSION['exp_user']['expires'] < time())
  10.                 {
  11.                     return false;
  12.                 }
  13.             else
  14.                 {
  15.                     return true;
  16.                 }
  17.         }
  18.        
  19.     public function form()
  20.         {
  21.             global $ACL_LANG;
  22.             $htmlForm = '<form id="frmlogin">'.
  23.                         '<label>';
  24.             switch(LOGIN_METHOD)
  25.             {
  26.                 case 'both':
  27.                     $htmlForm .= $ACL_LANG['USERNAME'].'/'.$ACL_LANG['EMAIL'];
  28.                     break;
  29.                 case 'email':
  30.                     $htmlForm .= $ACL_LANG['EMAIL'];
  31.                     break;
  32.                 default:
  33.                     $htmlForm .= $ACL_LANG['USERNAME'];
  34.                     break;
  35.             }                      
  36.             $htmlForm .= ':</label>'.
  37.                          '<input type="text" name="u" id="u" class="textfield" />'.
  38.                          '<label>'.$ACL_LANG['PASSWORD'].'</label>'.
  39.                          '<input type="password" name="p" id="p" class="textfield" />'.
  40.                          '<input type="submit" name="btn" id="btn" class="buttonfield" value="'.$ACL_LANG['LOGIN'].'" />'.
  41.                          '</form>';
  42.             return $htmlForm;
  43.         }
  44.        
  45.     public function signin($u,$p)
  46.         {
  47.             global $db_config,$user_config;
  48.            
  49.             $return = false;
  50.             if($u&&$p)
  51.                         {
  52.                             $this->db = @mysql_connect($db_config['server'],$db_config['user'],$db_config['pass']);
  53.                             if(!$this->db) return false;
  54.                            
  55.                             $opendb = @mysql_select_db($db_config['name'], $this->db);
  56.                             if(!$opendb) return false;
  57.                            
  58.                             $sql = "SELECT * FROM users WHERE ";
  59.                             $sql .= "username='".mysql_real_escape_string($u)."'";
  60.                             $sql .= " AND password = '$p'";
  61.                                            
  62.                             $rs = @mysql_query($sql,$this->db);
  63.                            
  64.                             if(!$rs) return false;
  65.                            
  66.                             if(mysql_num_rows($rs))
  67.                                 {
  68.                                     $this->set_session(array_merge(mysql_fetch_assoc($rs),array('expires'=>time()+(45*60))));
  69.                                     $return = true;
  70.                                 }
  71.                             mysql_free_result($rs);
  72.                             mysql_close($this->db);
  73.                             unset($rs,$sql);
  74.                         }
  75.             return $return;    
  76.         }
  77.        
  78.     public function register($ru,$rp)
  79.         {
  80.             global $db_config,$user_config;
  81.            
  82.             $return = false;
  83.            
  84.             if($ru&&$rp)
  85.                         {
  86.                             $this->db = @mysql_connect($db_config['server'],$db_config['user'],$db_config['pass']);
  87.                             if(!$this->db) return false;
  88.                            
  89.                             $opendb = @mysql_select_db($db_config['name'], $this->db);
  90.                             if(!$opendb) return false;
  91.                            
  92.                             $sql = "INSERT INTO users (username, password) VALUES ('bobby', 'billy')";
  93.                                            
  94.                             $rs = @mysql_query($sql,$this->db);
  95.                            
  96.                             if(!$rs) $return = true;
  97.                             mysql_free_result($rs);
  98.                             mysql_close($this->db);
  99.                             unset($rs,$sql);
  100.                         }
  101.             return $return;    
  102.         }
  103.  
  104.     private function set_session($a=false)
  105.         {
  106.             if(!empty($a))
  107.                 {
  108.                     $_SESSION['exp_user'] = $a;
  109.                 }
  110.         }
  111. }
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement