Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User {
- public $userName;
- public $userPassword;
- public $userEmail;
- public $userID;
- function __construct(){
- }
- function registerUser(){
- }
- function verifyCredentials($results){
- if($this->userName == $results['userName'] &&
- $this->userPassword == $results['userPassword']){
- //add other user data to class for input into session variables
- $this->userEmail = $results['userEmail'];
- $this->userID = $results['userID'];
- //start the session for authenticated user
- $this->setSession();
- }
- else{
- throw new Exception("Invalid username and/or password. [Error 1]");
- }
- }
- function changePassword($newPassword){
- }
- function setSession(){ //do I really need to explain this one?
- session_start();
- $_SESSION['userName'] = $this->userName;
- $_SESSION['userPassword'] = md5($this->userPassword);
- $_SESSION['userEmail'] = $this->userEmail;
- $_SESSION['userID'] = $this->userID;
- }
- function checkLogin(){
- if(isset($_SESSION['userName']) && isset($_SESSION['userID']) &&
- (mktime() - $_SESSION['userToken']) > 1800){
- session_unset();
- session_destroy();
- return false;
- }
- elseif(isset($_SESSION['userName']) && isset($_SESSION['userID']) &&
- (mktime() - $_SESSION['userToken']) < 1800){
- $this->userName = $_SESSION['userName'];
- $this->userPassword = $_SESSION['userPassword'];
- $this->userEmail = $_SESSION['userEmail'];
- $this->userID = $_SESSION['userID'];
- $_SESSION['userToken'] = mktime(); //user is active so update the token with the new time!!
- return true;
- }
- }
- function displayUserInfo(){
- echo "UserName: " .$this->userName. "<br>\n";
- echo "Password: " .$this->userPassword. "<br>\n";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement