HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/kms.komma.pro/wwwroot/app/models/m_login.class.php
<?php
/**
 * Created by Komma.pro
 * User: mikevandersanden
 * Date: 18/9/13
 */

require_once DOCUMENT_ROOT . 'lib/login/blacklist.class.php';



class Login_Model extends Model
{
    // Blacklist contains blocked ips
    private $_Blacklist;

    public function __construct()
    {
        parent::__construct();

        $this->_Blacklist = new Blacklist();
    }

    /*
     * Checks if the gate is opened.
     * Returns true of false
     */
    public static function gateIsOpen()
    {
        // Check if session exists
        if($userData = Session::get('user_data'))
        {
            //Set data to get from the database
            $fields = array('id','hash');
            $data = array_fill_keys($fields,'');

            //Get data from the database
            $Storage = new Storage();
            $Storage->setData($data);
            $Storage->setTableName( TABLE_PREFIX . 'kms_admin');
            $result = $Storage->select();
            $result = Fn::convert2D($result);
            foreach($result as $row)
            {
                $adminString = $row['id'].'_'.md5($row['hash']);
                if($adminString == $userData['string'])
                {
                    return true;
                }
            }
        }
        else
        {
            Session::destroy('user_data');
        }
        return false;
    }

    /*
     * Try to open the gate
     */
    public function openGate()
    {
        $user = $_POST['user'];
        $pass = $_POST['pass'];

        if( ! empty($user) && ! empty($pass))
        {
            if( ! $this->_Blacklist->get(array('user'=>$user,'ip'=>Session::get('ip') ) ))
            {
                if( ! Session::get('login_attempt') || Session::get('login_attempt') < 3)
                {
                    //Set data to get from the database
                    $fields = array('id','user','hash');
                    $data = array_fill_keys($fields,'');

                    //Get data from the database
                    $this->Storage->setTableName(TABLE_PREFIX . 'kms_admin');
                    $this->Storage->setData($data);
                    $this->Storage->addRule('user',$user);
                    $this->Storage->setScope(0,1);
                    $result = $this->Storage->select();

                    //Check if user found
                    if(count($result) > 0)
                    {
                        //Create hash from the entered password, and compare with the one in the database
                        $newHash = crypt($pass, $result['hash']);

                        if($newHash == $result['hash'])
                        {
                            $adminString = $result['id'].'_'.md5($result['hash']);

                            // Create user data array
                            $userData = array();
                            $userData['string'] = $adminString;
                            $userData['id'] = $result['id'];
                            $userData['name'] = $user;
                            $userData['login_time'] = time();

                            // Set user data
                            Session::set('user_data',$userData);
                            return true;
                        }
                        else
                        {
                            $this->errors[] = $this->lang['login_incorrect_user_pass'];
                        }
                    }
                    else
                    {
                        $this->errors[] = $this->lang['login_incorrect_user_pass'];
                    }
                }
                else
                {
                    $data['user'] = $user;
                    $data['ip'] = Session::get('ip');
                    $this->_Blacklist->put($data);
                    Fn::redirect(LANG_ROOT);
                }
            }
            else
            {
                $this->errors[] = 'ip blocked';
                Session::set('login_attempt',0);
            }
        }
        else
        {
            $this->errors[] = $this->lang['login_please_fill_both_forms'];
        }
        return false;
    }

    /*
     * Close the gate
     */
    public function closeGate()
    {
        Session::destroy('user_data');
    }


}