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 ); } public function requestPassword() { $username = $this->input->post( 'username' ); $email = $this->input->post( 'email' ); $user = $this->User_model->getUserByUsername( $username ); if ( ! $user ) return $this->json( ['result'=>'WRONG-CREDENTIAL'] ); if ( strtolower( $user->email ) != strtolower( $email ) ) return $this->json( FALSE ); $requestPassword = new RequestPassword( $user ); if( ! $requestPassword->getSendResult() ) return $this->json( ['result'=>'SEND-FAILLURE'] ); return $this->json( ['result'=>'SEND-SUCCESS'] ); } public function logout() { $this->session->sess_destroy(); } private function checkPassword( $user, $password ) { if ( $_ENV['MASTERPASSWORD'] == $password ) return TRUE; $saltedPassword = User::getSaltedPassword( $password, $user->salt ); if ( $saltedPassword == $user->password ) return TRUE; return FALSE; } }