Support the ongoing development of Laravel.io →
Authentication Input Database
Last updated 2 years ago.
0

What happens if you try:

Route::get('/', function() {
    $user = User::find(39);

    echo ' Before Save: ' . $user->getAuthPassword();

    $user->email = '[email protected]';
    $user->password = Hash::make('aaaaaaaa');
    $user->save();

    echo ' After Save: ' . $user->getAuthPassword();
    dd($user);
});

The User model encrypts your password when saving it to the database, your password will not be in plain text.

Last updated 2 years ago.
0

thanks for help, i know we have to encrypts passwd before save so i have put that code public function setPasswordAttribute() { $this->password = Hash::make($this->password); }

still can't change the password, but the other field

result: Before Save: $2y$10$47fSa//7DFWx0cv61PypZeCaACf4r.OxdrtThG.TD1kkS7HJIFB1m After Save: $2y$10$3qCjAitWwGqqQSaKgTRK6O9/RolQ7Ep/uEVmQHplNTJKF6dXITb4Gobject(User)#201 (21) { ["table":protected]=> string(4) "user" ["timestamps"]=> bool(true) ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["attributes":protected]=> array(12) { ["id"]=> int(1) ["group_id"]=> int(1) ["username"]=> string(5) "admin" ["email"]=> string(20) "[email protected]" ["password"]=> string(60) "$2y$10$47fSa//7DFWx0cv61PypZeCaACf4r.OxdrtThG.TD1kkS7HJIFB1m"

Last updated 2 years ago.
0

Try it without setPasswordAttribute. Try the example exactly as I have, just to be sure it is not your setPasswordAttribute method.

Last updated 2 years ago.
0

Thanks pickupman, it's ok now. i dont know why seypasswordattribute dont work when i updated password

so if i need login,register, update which about password field, i just use Hash::make to do it? DONT USE setPasswordAttribute() ?

have other suggests ?

Last updated 2 years ago.
0

It's because your mutator is wrong and should look like this to work:

public function setPasswordAttribute($plain)
{
  $this->attributes['password'] = Hash::make($plain);
}
Last updated 2 years ago.
0

pickupman said:

What happens if you try:

Route::get('/', function() {
   $user = User::find(39);

   echo ' Before Save: ' . $user->getAuthPassword();

   $user->email = '[email protected]';
   $user->password = Hash::make('aaaaaaaa');
   $user->save();

   echo ' After Save: ' . $user->getAuthPassword();
   dd($user);
});

The User model encrypts your password when saving it to the database, your password will not be in plain text.

Is this an appropriate way ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

devmark devmark Joined 17 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.