Fatal error: Call to undefined function password_verify ()

0

Someone can help me, the error appears:

  

Fatal error: Call to undefined function password_verify ()

My Code:

<?php
require_once 'sistema/init.php';
include 'includes/head.php';

$email = ((isset($_POST['email']))?sanitaze($_POST['email']):'');
$email = trim($email);
$password = ((isset($_POST['password']))?sanitaze($_POST['password']):'');
$password = trim($password);
$errors =  array();
?>
<div id="login-form">
    <div>
        <?php
            if($_POST){
                //Validação
                if(empty($_POST['email']) || empty($_POST['password'])){
                    $errors[] = 'Tem de preencher email e password!';
                }
                //validar email
                if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
                    $errors[] = 'Tem de preencher com um email válido!';
                }    
                //password tem mais de 6 caracteres
                if(strlen($password) < 6){
                    $errors[] = 'Password tem de ter pelo menos 6 caracteres!';
                }
                //Se email existe na base de dados
                $query1 = $ligacao->query("SELECT * FROM users WHERE email = '$email'");
                $user = mysqli_fetch_assoc($query1);
                $userCount = mysqli_num_rows($query1);
                if($userCount < 1){
                    $errors[] = 'Este email não existe na base de dados!';
                }

                if(!password_verify($password, $user['password'])){
                    $errors[] = 'A password não é igual com a da base de dados! Por favor, tente outra vez!';
                }    
                //ver se existem erros
                if(!empty($errors)){
                    echo display_errors($errors);
                } else{
                    //login user
                    $user_id = $user['id'];
                    login($user_id);
                }
            }
        ?>
    </div>
    <h2 class="text-center">Login</h2><hr>
    <form action="login.php" method="POST">
        <div class="form-group">
            <label for="email">Email:</label>
            <input type="text" name="email" id="email" class="form-control" value="<?php echo $email; ?>">
        </div>
        <div class="form-group">
            <label for="password">Password:</label>
            <input type="password" name="password" id="password" class="form-control" value="<?php echo $password; ?>">
        </div>
        <div class="form-group">
            <input type="submit" value="login" class="btn btn-primary">
        </div>
    </form>
    <p class="text-right"><a href="index.php" alt="home">Visitar Site</a></p>
</div>
<?php
include 'includes/footer.php';
?>

My roles:

<?php 
function display_errors($errors){
    $display = '<ul class="bg-danger">';
    foreach($errors as $error) {
        $display .= '<li class="text-danger">'.$error.'</li>';
    }
    $display .='</ul>';
    return $display;
}

function sanitaze($sujo){
    return htmlentities($sujo,ENT_QUOTES,"UTF-8");
}

function  euro($number){
    return '€ '.number_format($number,2);
}

function login($user_id){
    $_SESSION['SBUser'] = $user_id;
    global $ligacao;
    $date = date("Y-m-d H:i:s");
    $ligacao->query("UPDATE users SET ultimo_login = '$date' WHERE id = '$user_id'");
    $_SESSION['sucess_flash'] = 'Login feito com sucesso!';
    header('Location: index.php');
}

function loga(){
    if(isset($_SESSION['SBUser']) && $_SESSION['SBUser'] > 0){
        return true;
    }
    return false;
}

function login_error($url = 'login.php'){
    $_SESSION['error_flash'] = 'Tem de fazer o login para ter acesso!';
    header('Location:'.$url);
}

function permissao_error($url = 'login.php'){
    $_SESSION['error_flash'] = 'Não tem permissão para aceder esta página!';
    header('Location:'.$url);
}

function tem_permissao($permissao = 'admin'){
    global $user_data;
    $permissoes = explode(',',$user_data['permissao']);
    if(in_array($permissao,$permissoes,true)){
        return true;
    }
    return false;
}
?>
    
asked by anonymous 22.07.2017 / 12:01

1 answer

3

The function password_verify only exists from PHP version 5.5, so it certainly is to run that code in a lower version.

You can confirm the version you have by using phpinfo , calling it only:

<?php
phpinfo();
?>

No phpinfo version appears at the top:

    
22.07.2017 / 12:21