简体   繁体   中英

Hash Provider in Laravel

I've followed this tutorial to create a custom hash and I've implemented Multi-Auth system in Laravel 5.3 too (works fine) but I want to know:

Can I use multiple DB hashes between these authentications?

  1. Admin Area (I can use bycrypt by default)
  2. Customer Area (I can use md5 for example)

Is that possible?

Before you ask: Yes, that's necessary for my project!

If you already have a working multi auth system and an extra hasher that uses md5, you can inject it in your custom auth provider. Here are possible steps you might require.

If you only want another hasher you may try using core provider:

  1. Create a My\\Library\\MyHasher implementing core contract https://github.com/illuminate/contracts/blob/master/Hashing/Hasher.php (as in the tutorial)

  2. Register / inject it in the AuthServiceProvider boot method under your app's providers, something like that:

    // instantiate or inject the new hasher as $hasher

    Auth::provider('md5user', function($app, array $config) use ($hasher) { return new \\Illuminate\\Auth\\EloquentUserProvider\\EloquentUserProvider($hasher, $config['model']); });

If you want to be able to tweak the provider functionality:

  1. Create a My\\Library\\MyUserProvider similar to a core one https://github.com/illuminate/auth/blob/master/EloquentUserProvider.php and change what you need

  2. Create a My\\Library\\MyHasher implementing core contract https://github.com/illuminate/contracts/blob/master/Hashing/Hasher.php

  3. Register / inject them in the AuthServiceProvider boot method under your app's providers:

    // instantiate or inject the new hasher as $hasher

    Auth::provider('md5user', function($app, array $config) use ($hasher) { return new \\My\\Library\\MyUserProvider($hasher, $config['model']); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM