Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJosh O.
2,370 PointsReturn 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?
<?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');
}