benshepherd icon

badcode

benshepherd | PRO | 06/05/15 12:47:06 PM UTC | 0 ⭐ | 2353 👁️ | Never ⏰ | []
PHP |

1.44 KB

|

None

|

0 👍

/

0 👎

<?php
 
    class Account {
        
        private static $f = "data/.account";
        
        private static function GetDetails() {
            
            if(file_exists(self::$f)) {
                
                $arr = json_decode(file_get_contents(self::$f),true);
                
                return $arr;
            }
            else {
                die("Error getting login information. Please contact developer.");
            }
            
        }
    
        public static function Auth($email,$password) {
        
            $email = strtolower($email);
        
            $logged_in = false;
            $match = self::GetDetails();
            
            if((isset($_POST["email"]) ? $_POST["email"] : "") == $match["email"] && (isset($_POST["pass"]) ? $_POST["pass"] : "") == $match["pass"]) {
                
                SessionManager::Set((isset($_POST["remember"]) ? $_POST["remember"] : false) == "1" ? true : false);
                
                $logged_in = true;
                $message = "You have been logged in.";
                
            } else {
                
                $message = "Incorrect email or password.";  
            }       
            
            
            return array("status" => $logged_in, "msg" => $message);
        }
        
        public static function ChangePwd($old,$new,$confirm) {
        
            if($new != $confirm) {
                return array(false,"Passwords do not match");   
            }
            
            $arr = self::GetDetails();
            
            if($old != $arr["pass"]) {
                return array(false,"Current password is incorrect");    
            }
            
            $arr["pass"] = $new;
            
            $fw = fopen(self::$f,"w");
            fwrite($fw,json_encode($arr));
            fclose($fw);
            
            return array(true,"Passwords have been changed");
            
        }
    }
 
?>

Comments