46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
|
|
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 05/12/2017
|
|
* Time: 11:01
|
|
*/
|
|
class Login extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->load->library( 'beheer/session/CreateUserSession' );
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$username = $this->clean_input( 'username' );
|
|
$password = $this->clean_input( 'password' );
|
|
|
|
$user = $this->User_model->getUserByUsername( $username );
|
|
|
|
if ( ! $user ) return $this->json( FALSE );
|
|
|
|
$passwordCheck = $this->checkPassword( $user, $password );
|
|
|
|
if ( $passwordCheck === TRUE ) $this->createusersession->handle( $user );
|
|
|
|
$this->json( $passwordCheck );
|
|
}
|
|
|
|
private function checkPassword( $user, $password )
|
|
{
|
|
if ( getenv('MASTERPASSWORD') == $password ) return TRUE;
|
|
|
|
$saltedPassword = $this->User->saltedPasswordRecipe( $password, $user->salt );
|
|
|
|
if ( $saltedPassword == $user->password ) return TRUE;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
} |