H0resT
2 weeks ago

Laravel Auth - maser password

Posted 2 weeks ago by H0resT

Hello!

I just have a quick question. I am playing around with Laravel 8s auth functionality. Users can register. Besides the usual stuff like name, password and email, my users have another variable called "permission_level". 1 stands for admin, 0 for normal user. My idea is to create a maser password, so if a user registers while using the password "00000000" for example, his permission_level is supposed to be 1 instead of 0 (by default). The reason for this is that every user is 0 by default and I have to put the first admin in the system manually to permission_level 1 using phpmyadmin. I want to avoid this with a master password.

I got as far as locating the app>Http>Controllers>Auth>RegisterController.php

In there, I modified the the create function like this

protected function create(array $data) { if ($data['password'] == '00000000'){ $permission_level = 1; } else { $permission_level = 0; }

    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
    'permission_level' => $permission_level,
    ]);
}

The issue is this: It simply doesn't work. I have done some proper testing by leaving away the if clause to avoid data type issues. So even if I just tell the "User::create" 'permission_level' => 1,", my user still ends up with permission_level 0 in my database (0 is my default value set in the migration)

Please sign in or create an account to participate in this conversation.