View sourcecode

The following files exists in this folder. Click to view.

login.class.php

32 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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";
    }
}
?>