How to use password_hash Register And Login

前端 未结 1 1058
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 09:08

I\'m trying to figure out how to use password_hash on register and login systems.

Currently I\'m using password_hash like this to register my users.

$pas         


        
相关标签:
1条回答
  • 2021-01-28 09:59

    Ok I made this work with password_verify()

    $usuario = $_POST["Nick"];
    $contra = $_POST["Pass"];   
    $stmt = $conn->prepare("SELECT Nick, Password FROM usuario WHERE Nick = ?");
    $stmt->bind_param( "s", $usuario); 
    $stmt->execute();
    $stmt->store_result(); 
    $stmt->bind_result($a, $b);   
    
    if($stmt->fetch() == 0){ 
        header("Location: ../Entrar.php?message=Error");
        exit();
    }
    else {  
        if(password_verify($contra, $b)) {
            session_start(); 
            $_SESSION['Usuario'] = $a; 
            $_SESSION['estado'] = 'Autenticado';  
            header("Location: ../../Index.php"); 
            exit; 
        }
        else{ 
            header("Location: ../Entrar.php?message=Error");
            exit;
        }
    } 
    

    Thank you for all those comments. And yes martinstoeckli that was the answer to my question thank you

    0 讨论(0)
提交回复
热议问题