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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Seo Park](https://secure.gravatar.com/avatar/1059bb85747ab03a9a5d9f2059ede88a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Seo Park
1,346 PointsI don't know whats wrong.
If I add path it will still display error please help
<?php
function newPasswordValid($userPassword, $currPassword, $newPassword, $confirmNewPassword){
$currPassword = request()->get('current_password');
$newPassword = request()->get('password');
$confirmPassword = request()->get('confirm_password');
}
1 Answer
![Corey Cramer](https://secure.gravatar.com/avatar/79beb08afb12aac46d34187b9d5374a6?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Corey Cramer
9,453 PointsBecause we are writing a function we should depend on the variables being passed into it as opposed to trying to fetch them inside of the function by accessing the request directly. Operating on that premise we compare the current password to the one the user supplied in the form to make sure they match and we make sure that their new password matches the confirmation box. If both of those pass, we return a new hashed password to store otherwise we return false.
<?php
function newPasswordValid($userPassword, $currPassword, $newPassword, $confirmNewPassword) {
if (password_verify($currPassword, $userPassword) &&
$newPassword == $confirmNewPassword)
{
return password_hash($newPassword, PASSWORD_DEFAULT);
}
return false;
}