The following files exists in this folder. Click to view.
login.class.php32 lines UTF-8 Unix (LF)
<?php
class LoginUser{
private $username;
private $password;
public $error;
public $success;
private $storage = "data.json";
private $stored_users;
public function __construct($username, $password){
$this->username = $username;
$this->password = $password;
$this->stored_users = json_decode(file_get_contents($this->storage), true);
$this->login();
}
private function login(){
$lowercaseUser = strtolower($this->username);
foreach($this->stored_users as $user){
if(strtolower($user["username"]) == $lowercaseUser){
if(password_verify($this->password, $user["password"])){
session_start();
$_SESSION["user"] = $user["username"];
header("location: account.php"); exit();
}
}
}
return $this->error = "Fel användarnamn eller lösenord";
}
}
?>