<?php

require __DIR__ . '/../common.php';
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e;
if (empty($_REQUEST['login']) || empty($_REQUEST['password'])) {
    echo '{"status":"ERROR","results":false,"error":"Login and password required"}';
    exit;
}
$login = $_REQUEST['login'];
$password = $_REQUEST['password'];
$mac = isset($_REQUEST['mac']) ? $_REQUEST['mac'] : '';
$possible_user = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->from('users')->where(['login' => $login])->get()->first();
if (\strlen($possible_user['password']) == 32 && \md5(\md5($password) . $possible_user['id']) == $possible_user['password'] || \strlen($possible_user['password']) < 32 && $password == $possible_user['password']) {
    if ($possible_user['mac'] == '' || \strtolower($possible_user['mac']) == \strtolower($mac)) {
        $user = $possible_user;
    }
}
if (empty($user)) {
    echo \error('User not exist or login-password mismatch');
} else {
    echo '{"status":"OK","results":true}';
}
