Override laravel 4's authentication methods to use custom hasing function

后端 未结 4 697
长发绾君心
长发绾君心 2021-02-08 16:09

I have a table in my database with users. Their password are generated with my own custom hashing function.

How do i override the Authentication methods in laravel 4 to

4条回答
  •  渐次进展
    2021-02-08 16:40

    Warning: I can't ensure this is works out of the box and there may be a few gotchas here and there. Keep in mind Laravel 4 is still on development. Wish I could provide a more precise answer, but codebase is still going through many changes and not everything is properly documented. Anyway, you are looking for something like this:

    // on config/auth.php
    'driver' => 'custom'
    
    // on start/global.php
    Auth::extend('custom', function() {
        // CustomUserProvider is your custom driver and should
        // implement Illuminate\Auth\UserProviderInterface;
        return new Guard(new CustomUserProvider, App::make('session'));
    });
    

    If this doesn't give you enough information to start, you should be able to figure it out by taking a look at those classes below:

    EloquentUserProvider and DatabaseUserProvider
    These classes are the currently supported authentication drivers. They should guide you on how to create your CustomUserProvider (or any name you like really).

    Manager
    This is the base class for anything that accepts custom drivers (including the AuthManager). It provides the methods for registering them like you do in Laravel 3.

提交回复
热议问题