Advertisement
Guest User

PHP user

a guest
Feb 13th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. class User{
  3.  
  4.     public $id;
  5.     public $username;
  6.     public $email;
  7.  
  8.     private $password;
  9.  
  10.     public  $loggedin = false;
  11.     //whatever you require for a login here.
  12.    
  13.     public function __construct($username,$password){
  14.         $sql = new SimpelSQL(); //plugin I wrote and use to make SQL more simple and faster, otherwise to much code... :)
  15.         $this->username = $username;
  16.         $this->password = $password;
  17.         $this->id = $sql->select("id","users",array("username" => $this->username));
  18.         $this->email = $sql->select("email","users",array("username" => $this->username));
  19.     }
  20.  
  21.     public function login(){
  22.         $oldpassword = $sql->select("password","users",array("id" => $this->id));
  23.         if(password_verify($this->password,$oldpassword)){
  24.             $this->setSession();
  25.             $this->loggedin = true;
  26.         }
  27.         return $this->loggedin;
  28.     }
  29.  
  30.     public function create($username,$email,$password){
  31.         if($sql->exists("users",array("username" => $username))){
  32.             $sql->insert("users",array(
  33.                 0,
  34.                 $username,
  35.                 $email,
  36.                 $password
  37.                 ));
  38.             return true;
  39.         }
  40.         return false;
  41.     }
  42.  
  43.     public function setSession(){
  44.         $_SESSION["id"] = $this->id;
  45.         $_SESSION["username"] = $this->username;
  46.         return $_SESSION;
  47.     }
  48.  
  49.     public function isLoggedIn(){
  50.         return $this->loggedin;
  51.     }
  52.  
  53.     public function verify_user(){
  54.         if($sql->exists("users",array("username" => $this->username))){
  55.             return true;
  56.         }
  57.         return false;
  58.     }
  59.  
  60.     public function setPassword($password){
  61.         $this->password = $password;
  62.         return $this;
  63.     }
  64.     public function getPassword($password){
  65.         return $this->password;
  66.     }
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement