Gokuka

Untitled

May 16th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <?php
  2.  
  3. class Logins extends DB {
  4.  
  5.     private $table = 'users';
  6.     private $prefix = 'temp_';
  7.  
  8.     //Encrypt password new.
  9.     private function Cript($Password) {
  10.         return md5($Password);
  11.     }
  12.  
  13.     //Function account validation
  14.     private function Validate($Email, $Password) {
  15.         $Password = $this->Cript($Password);
  16.  
  17.         try {
  18.             $Validates = self::Connect()->prepare("SELECT * FROM " . $this->table . " WHERE email = ? AND password = ? AND status='1'");
  19.             $Validates->execute(array($Email, $Password));
  20.             return ($Validates->rowCount() >= 1) ? true : false;
  21.         } catch (PDOException $e) {
  22.             echo $e->getMessage();
  23.             return false;
  24.         }
  25.     }
  26.  
  27.     //login in panel
  28.     public function LogIn($Email, $Password) {
  29.         if ($this->Validate($Email, $Password)) {
  30.             $_SESSION[$this->prefix . 'email'] = $Email;
  31.             $_SESSION[$this->prefix . 'password'] = $Password;
  32.             return true;
  33.         } else {
  34.             return false;
  35.         }
  36.     }
  37.  
  38.     //Verifies that is already logged in
  39.     public function isLogged() {
  40.         if (isset($_SESSION[$this->prefix . 'email']) && isset($_SESSION[$this->prefix . 'password'])) {
  41.             return true;
  42.         } else {
  43.             return false;
  44.         }
  45.     }
  46.  
  47.     public function Logout() {
  48.         if ($this->isLogged()) {
  49.             unset($_SESSION[$this->prefix . 'email']);
  50.             unset($_SESSION[$this->prefix . 'password']);
  51.             session_destroy();
  52.             return true;
  53.         } else {
  54.             return false;
  55.         }
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment