Advertisement
benshepherd

badcode

Jun 5th, 2015
2,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.  
  3.     class Account {
  4.        
  5.         private static $f = "data/.account";
  6.        
  7.         private static function GetDetails() {
  8.            
  9.             if(file_exists(self::$f)) {
  10.                
  11.                 $arr = json_decode(file_get_contents(self::$f),true);
  12.                
  13.                 return $arr;
  14.             }
  15.             else {
  16.                 die("Error getting login information. Please contact developer.");
  17.             }
  18.            
  19.         }
  20.    
  21.         public static function Auth($email,$password) {
  22.        
  23.             $email = strtolower($email);
  24.        
  25.             $logged_in = false;
  26.             $match = self::GetDetails();
  27.            
  28.             if((isset($_POST["email"]) ? $_POST["email"] : "") == $match["email"] && (isset($_POST["pass"]) ? $_POST["pass"] : "") == $match["pass"]) {
  29.                
  30.                 SessionManager::Set((isset($_POST["remember"]) ? $_POST["remember"] : false) == "1" ? true : false);
  31.                
  32.                 $logged_in = true;
  33.                 $message = "You have been logged in.";
  34.                
  35.             } else {
  36.                
  37.                 $message = "Incorrect email or password."; 
  38.             }      
  39.            
  40.            
  41.             return array("status" => $logged_in, "msg" => $message);
  42.         }
  43.        
  44.         public static function ChangePwd($old,$new,$confirm) {
  45.        
  46.             if($new != $confirm) {
  47.                 return array(false,"Passwords do not match");  
  48.             }
  49.            
  50.             $arr = self::GetDetails();
  51.            
  52.             if($old != $arr["pass"]) {
  53.                 return array(false,"Current password is incorrect");   
  54.             }
  55.            
  56.             $arr["pass"] = $new;
  57.            
  58.             $fw = fopen(self::$f,"w");
  59.             fwrite($fw,json_encode($arr));
  60.             fclose($fw);
  61.            
  62.             return array(true,"Passwords have been changed");
  63.            
  64.         }
  65.     }
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement