PHP Introduction to User Authentication in PHP Setting Up Authorization Password Hashing

Josh O.
Josh O.
658 Points

Return a Value??

I am working on the password update exercise. Error states that the function should return 2 values. I have the four variables it is discussion. How do I "return" a value? What does the word "return" mean in this context? I have it where it will interact with the database. Because of the error I cannot see what it would do in a browser. Does return mean that I was able to store variables in the database?

index.php
<?php

function newPasswordValid($userPassword, $currentPassword, $newPassword, $confirmNewPassword) {
  $userPassword = request ()-> get('$user_Password');
  $currentPassword = request ()-> get('current_password');
  $newPassword = request()->get('password');
  $confirmNewPassword = request()->get('confirm_new_password');

  if ($newPassword != $confirmPassword){
    $session-getFlashBag()-> add('error','New passwords do not appear to match. Sorry, please try again.');
    redirect('/account.php');
}

$user = getAuthenticatedUser();
if (empty($user)) {
  $session->getFlashBag()->add('error', 'Some Error Happened. Try again. If it continues, please log out and back in.');
    redirect('/account.php');
}

if (!password_verify($currentPassword, $user['password'])){ #brackets seem to indicate we are interacting with the database. 
 $session->getFlashBag()->add('error', 'Current password is incorrect, please try again.');
   redirect('/account.php');
}

$hashed = password_hashed($newPassword, PASSWORD_DEFAULT);

if (!updatePassword($hashed, $user['id'])){
  $session->getFlashBag()->addd('error', 'Could not update password. Please try again.');
  redirect('/account.php');
}

$session->getFlashBag()->add('success', 'Password Updated!');
  redirect('/account.php');  
}