Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. class User {
  4.  
  5.          public $userName;
  6.          public $userPassword;
  7.          public $userEmail;
  8.          public $userID;
  9.          
  10.     function __construct(){
  11.    
  12.     }
  13.        
  14.         function registerUser(){
  15.            
  16.         }
  17.        
  18.         function verifyCredentials($results){
  19.             if($this->userName == $results['userName'] &&
  20.                 $this->userPassword == $results['userPassword']){
  21.                     //add other user data to class for input into session variables                
  22.                     $this->userEmail = $results['userEmail'];
  23.                     $this->userID = $results['userID'];
  24.                     //start the session for authenticated user
  25.                     $this->setSession();
  26.             }
  27.             else{
  28.                 throw new Exception("Invalid username and/or password. [Error 1]");
  29.             }
  30.         }
  31.        
  32.         function changePassword($newPassword){
  33.        
  34.         }
  35.        
  36.         function setSession(){ //do I really need to explain this one?
  37.             session_start();
  38.             $_SESSION['userName'] = $this->userName;
  39.             $_SESSION['userPassword'] = md5($this->userPassword);
  40.             $_SESSION['userEmail'] = $this->userEmail;
  41.             $_SESSION['userID'] = $this->userID;
  42.            
  43.         }
  44.        
  45.         function checkLogin(){
  46.             if(isset($_SESSION['userName']) && isset($_SESSION['userID']) &&
  47.                 (mktime() - $_SESSION['userToken']) > 1800){
  48.                     session_unset();
  49.                     session_destroy();
  50.                     return false;
  51.             }
  52.             elseif(isset($_SESSION['userName']) && isset($_SESSION['userID']) &&
  53.                     (mktime() - $_SESSION['userToken']) < 1800){
  54.                         $this->userName = $_SESSION['userName'];
  55.                         $this->userPassword = $_SESSION['userPassword'];
  56.                         $this->userEmail = $_SESSION['userEmail'];
  57.                         $this->userID = $_SESSION['userID'];
  58.                         $_SESSION['userToken'] = mktime(); //user is active so update the token with the new time!!
  59.                         return true;
  60.             }
  61.         }
  62.        
  63.         function displayUserInfo(){
  64.             echo "UserName: " .$this->userName. "<br>\n";
  65.             echo "Password: " .$this->userPassword. "<br>\n";
  66.         }
  67.        
  68. }
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement