Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. class User {
  2.  
  3.     private $user_id;
  4.     private $username;
  5.     private $password;
  6.     private $authentication;
  7.     private $token;
  8.    
  9.   // costruttore
  10.     public function __construct($idu=NULL, $usr=NULL, $psw=NULL, $aut=NULL ) {
  11.  
  12.         if ( $idu ) $this->user_id = $idu;
  13.         if ( $usr ) $this->username = $usr;
  14.         if ( $psw ) $this->password = md5($psw);
  15.         if ( $aut ) $this->authentication = $aut;
  16.        
  17.         if ( $this->password != NULL)
  18.             $this->token = substr($this->password,0,5);
  19.         else {
  20.             srand(mktime());
  21.             $this->token = substr(md5(rand()),0,5);
  22.         }
  23.     }
  24.  
  25.     function setUsr( $usr ) {
  26.         $this->username = $usr;
  27.     }
  28.    
  29.     function setPsw( $psw ) {
  30.       $this->password = md5($psw);
  31.     }
  32.    
  33.     function setAut( $aut ) {
  34.       $this->authentication = $aut;  
  35.     }
  36.    
  37.     function getUsr() {
  38.       return $this->username;
  39.     }
  40.    
  41.     function getPsw() {
  42.       return $this->password;
  43.     }
  44.    
  45.     function getAut() {
  46.       return $this->authentication;
  47.     }
  48.    
  49.     public function getTok() {
  50.       return $this->token;
  51.     }
  52.    
  53.     function getIdu() {
  54.       return $this->user_id;
  55.     }
  56. }
  57.  
  58. /**/
  59. $db = new DBO();
  60.             $db->connetti("kbsalso");
  61.            
  62.             $query = "SELECT * FROM user WHERE user_account = '".trim($_POST['usr'])."' LIMIT 1";
  63.             $res = $db->estrai($db->query($query));
  64.            
  65.             if ( $res["user_password"] == md5(trim($_POST['psw'])) ) {
  66.                 $user = new User($res["user_id"],$res["user_account"],$res["user_password"],$res["user_permission"] );
  67.                 $data['code'] = 0;
  68.         session_start();
  69.        
  70.                 $data["pagelink"] = "index.php?page=main&token=".$user->getTok;
  71.             } else $data['code'] = 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement