dev-master
9999999-devBasic tools for updating a user's password on create/update
MIT
by Jeff Kilroy
Wallogit.com
2017 © Pedro Peláez
Basic tools for updating a user's password on create/update
Basic tools for updating a user's password on create/update, (*1)
This package adds a very simple trait to automatically save the user id who created this model., (*2)
Simply add the "\BinaryCabin\LaravelPassword\Traits\HasPassword;" trait to your model:, (*3)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use \BinaryCabin\LaravelAuthor\Traits\HasAuthorUser;
}
Now when you create a new user: - A temporary password will be generated if it isn't added in the ::create attributes - A password passed in the attributes will automatically be hashed, (*4)
And when calling $user->update: - A password passed in the attributes will automatically be hashed, (*5)
NOTE: Be careful to remove any existing hashing that exists in your application, as this will cause the password to be hashed twice. For example, Laravel's default register controller contains:, (*6)
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
Since the User::create method will now hash the included password, you can update this to:, (*7)
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => $data['password'],
]);
Additionally, the default ResetPasswordController will hash the User's password as well. Add this to the controller to overwrite this functionality:, (*8)
protected function resetPassword($user, $password){
$user->password = $password;
$user->setRememberToken(\Illuminate\Support\Str::random(60));
$user->save();
event(new \Illuminate\Auth\Events\PasswordReset($user));
$this->guard()->login($user);
}
Basic tools for updating a user's password on create/update
MIT