Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

500
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda