<?php

include '../common.php';
use Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2;
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\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2::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}';
}
