DEV Community

Cover image for Login Customization in Laravel 8

Login Customization in Laravel 8

AibnuHibban on September 12, 2020

Bismillah this time I can still write an article that hopefully can be useful for friends who read... As the title implies, I want to share a lit...
Collapse
 
lootfi profile image
Lotfi

Thanks for the post!

One remark on the "Change the Minimum Requirement Password" part

you should never mess with your vendor files unless you are pushing them to production.

Here's how you can customize the minimum requirement:
jetstream.laravel.com/1.x/features...

Collapse
 
aibnuhibban profile image
AibnuHibban • Edited

Yeah .. Thanks for reminding .. 👌

Collapse
 
bodnarlajostibor profile image
Lajos

I'm facing the same issue, but that Jetstream documentation is unclear for me.

Can you please help me where to put there codes like "(new Password)->length(10)"?

Collapse
 
lootfi profile image
Lotfi

You can do that in "App\Actions\Fortify\PasswordValidationRules" where you will find a "passwordRules" method

Thread Thread
 
bodnarlajostibor profile image
Lajos

An in that, I can see one line:
return ['required', 'string', new Password, 'confirmed'];

Where should I put the suggested "(new Password)->length(10)", for example?

Thread Thread
 
tuckbloor profile image
Chris

protected function passwordRules()
you need to add the following

return ['required', 'string', (new Password)->length(10), 'confirmed'];
Enter fullscreen mode Exit fullscreen mode
Collapse
 
aregonyazilim profile image
aregonyazilim

I used the following code;
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Laravel\Fortify\Fortify;

class LoginController extends Controller
{
public function authenticate(Request $request)
{

    Fortify::authenticateUsing(function (Request $request) {

        $user = User::where('email', $request->email)->first();

        if ($user && Hash::check($request->password, $user->password)) {
            print_r($user);
            return $user;
        }
    });

}

}
But it doesn't work. Where am I going wrong?

Collapse
 
lootfi profile image
Lotfi

Maybe your login form action is not making a request to your LoginController?

Route::post('authenticate', [LoginController::class, 'authenticate'])->name('authenticate');
<form method="POST" action="{{ route('authenticate') }}">
Collapse
 
oceanrational profile image
VikramJS

Well. It's good you trying it on newer version. unfortunatly i havent tried yet. I hope someone will definitly answer this.

Collapse
 
aibnuhibban profile image
AibnuHibban

Are you routing the controller correctly?
If there is an error what is the error?

Collapse
 
localpath profile image
Garrick Crouch

You should override the properties on the vendor class, it includes a setter ->

<?php

namespace App\Actions\Fortify;

use Laravel\Fortify\Rules\Password;

trait PasswordValidationRules
{

    /**
     * Get the validation rules used to validate passwords.
     *
     * @return array
     */
    protected function passwordRules()
    {
        return ['required', 'string', (new Password())->length(6), 'confirmed'];
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mafalda2007 profile image
Mafalda

Hi, very good!
If I want to have two places to authenticate the user? how would it be?

  1. The user must login to the local database (this is my new DB).
  2. In case of error, validate in the second remote database via Webservice. (this's de old old old DB)
Collapse
 
seddka profile image
Seddik Tagadirt

Thanks for the post! nice article Abdullah.
I have a question: Can i specify multiple guards in fortify? by default it uses web guard, but what if i have and admin in my Auth config and wants to make use of it with fortify? any ideas?

Collapse
 
javierx2010 profile image
Javier Escobar

Dude! You are awesome! I spent days trying to find answers on Stackoverflow and Laracast and you solved all my questions in a condensed yet wonderful post!

Thanks a lot!

Collapse
 
alarafatsiddique profile image
Al-ArafatSiddique

What about RegisterController? Can u please clear it like i did for loginController...

Collapse
 
moduledev profile image
Sergey

Thanks a lot for article! But can you explain how to make custom register (for instance we want to use several models User,Admin)?

Collapse
 
4n_najib profile image
An Najib

how about creating remember me token when login. I want to manualy create theme