Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

498
Visualizações
PHP: password_verify always returns false

somehow I'm struggling with something that I expected to be straightforward. I created the following code just for testing purposes and I expected it to give the answer "valid password" in case the provided $login_password is "123456". But I always get "Invalid password."

$login_password = $_POST['login_password'];
$login_password_hash = password_hash($login_password, PASSWORD_DEFAULT);

$target_password = '123456';
$target_password_hash = password_hash($target_password, PASSWORD_DEFAULT);

if ( password_verify($login_password_hash, $target_password_hash) ) {
    echo "Valid password.";
    } 
else {
    echo "Invalid password.";
    }

I even get "Invalid password." when changing the password_verify to compare the same variable with itself:

password_verify($login_password_hash, $login_password_hash)

A little help is highly appreciated :)

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Change the first line in this

if ( password_verify($login_password_hash, $target_password_hash) ) {
    echo "Valid password.";
} 

To

if ( password_verify($login_password, $target_password_hash) ) {
over 4 years ago · Santiago Trujillo Relatório

0

You need to pass simple text password without hash as first param

if ( password_verify($login_password , $target_password_hash) ) {
    echo "Valid password.";
    } 
else {
    echo "Invalid password.";
    }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda