/*
Navicat MySQL Data Transfer

Source Server         : Pure WPanel
Source Server Version : 50505
Source Host           : purefitness.es:3306
Source Database       : wpanelh_master

Target Server Type    : MYSQL
Target Server Version : 50505
File Encoding         : 65001

Date: 2025-01-29 10:56:19
*/


  /*
    PWD: Encriptada... 1234 
    PASSWORD_BCRYPT, ['cost' => 12]
  */

/* PHP PARA CREAR Y CHECK 

  function FUNC_CrearPWD($pwd)
{
    $pwd_enc = password_hash($pwd, PASSWORD_BCRYPT, ['cost' => 12]);
    return $pwd_enc;
}

function FUNC_CheckPWD($pwd, $pwd_codif)
{
    if (password_verify($pwd, $pwd_codif)) {
        return true;
    } else {
        return false;
    }
}


function FUNC_CheckUser($con, $db, $email, $pwd)
{

    $sqlVerificandoLogin = ("SELECT users_pw FROM pure_users WHERE users_email ='" . $email . "'");
    $resultLogin = mysqli_query($db, $sqlVerificandoLogin) or die(mysqli_error($con));
    $numLogin = mysqli_num_rows($resultLogin);
    echo $numLogin;
    echo '<br>';
    if ($numLogin > 0) {

        while ($rowData = mysqli_fetch_assoc($resultLogin)) {
            $passwordBD = $rowData['users_pw'];
            echo $passwordBD;
            echo '<br>';
            echo $pwd;
            echo '<br>';
            if (FUNC_CheckPWD($pwd, $passwordBD)) {
                return true;
            }
        }
    } else {
        return false;
    }
}

function FUNC_CargarUsuario($con, $db, $email)
{
    $sqlVerificandoLogin = ("SELECT users_id,users_name,users_admin FROM pure_users WHERE users_email ='" . $email . "'");
    $resultLogin = mysqli_query($db, $sqlVerificandoLogin) or die(mysqli_error($con));
    $numLogin = mysqli_num_rows($resultLogin);
    if ($numLogin > 0) {
        while ($rowData = mysqli_fetch_assoc($resultLogin)) {
            session_start();
            $user[0] = $rowData['users_id'];
            $user[1] = $rowData['users_name'];
            $user[2] = $email;
            $user[3] = $rowData['users_admin'];
        }
        return $user;
    }
}

function FUNC_AbrirSesion($con, $db, $email)
{
    $sqlVerificandoLogin = ("SELECT users_id,users_name,users_admin,users_idCom,users_direccion,users_instalacion,users_comercial,users_tecnicos FROM pure_users WHERE users_email ='" . $email . "'");
    $resultLogin = mysqli_query($db, $sqlVerificandoLogin) or die(mysqli_error($con));
    $numLogin = mysqli_num_rows($resultLogin);
    //echo $numLogin;
    //echo '<br>';
    if ($numLogin > 0) {
        while ($rowData = mysqli_fetch_assoc($resultLogin)) {
            session_start();
            $_SESSION['IdUser'] = $rowData['users_id'];
            $_SESSION['nameUser'] = $rowData['users_name'];
            $_SESSION['emailUser'] = $email;
            $_SESSION['UserAdmin'] = $rowData['users_admin'];
            $_SESSION['UserIdCom'] = $rowData['users_idCom'];
            $_SESSION['UserDirec'] = $rowData['users_direccion'];
            $_SESSION['UserInst'] = $rowData['users_instalacion'];
            $_SESSION['UserCom'] = $rowData['users_comercial'];
            $_SESSION['UserTecn'] = $rowData['users_tecnicos'];
        }
        return true;
    }
}

*/
