Encrypt passwords

Asked

Viewed 1,556 times

-1

I need to generate a default password for users of my table login. The password must be the same for all users for the first access to the system. Registration already exists, but I have to modify passwords. The problem happens when updating passwords, only the first user of the table can do the login.

public function recadastroSenha(){

    $users = User::whereRaw("flag_del = 0 ")->get();

    foreach($users as $user){

        $senha = "senha123";
        $user->password = bcrypt($senha);            
    } 
    $user->save();
}

Even updating all table rows with different encryption, only the first user performs the login.

  • 1

    Insert the $user->save(); inside the foreach also

  • @Miguel thanks for the answer, I’ve tried this way too and only works with the first record of the table.

  • Remember you’re selecting everyone whose flag = 0, is that n is? Anyway the $user->save(); must be inside the foreach, otherwise it will only insert the die for the last $user who went through the foreach

  • That, the users with this flag are the "not deleted" in my bd, even saving inside the foreach it seems that the system only accepts a different password for each user, even with different strings.

  • Strange that. And can only enter later with the first $user?

  • yeah, that’s what happens.

  • I wonder if that’s all there is flag_del = 0? try to make echo $user->password. '<br>';, to see how many times it prints

  • all are as flag_del and happens to change passwords, I checked now that the first and last registration can access.

Show 3 more comments

1 answer

0

It would have to be the method save within the for for change the password:

public function recadastroSenha(){

    $users = User::whereRaw("flag_del = 0 ")->get();

    foreach($users as $user){

        $senha = "senha123";

        $user->password = bcrypt($senha);

        $user->save();

    } 

}
  • unfortunately the problem is not this.

  • What’s the problem please report?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.