Skip to content

Using the Auth module: What is the best way to change a password? #247

Answered by ibnsultan
agedeo asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the Leaf Password module to do that, which is aleady loaded as a Helper class

assuming you're using a leaf mvc, a rough implementtion would be something like this

use App\Models\User;
use Leaf\Helpers\Password;

$oldPassword = 'theOldPass';
$newPassword = 'theNewPass';

$user = User::find(:id);
if(Password::verify($oldPassword, $user->password){
    $user->password = Password::hash($newPassword)
    $user->save();
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by agedeo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants