Different database:
I would say that the best way to do so is to define a separate connection for the specific model.
So, in your database.php config, add another connection (let's name it mysql_auth).
To use it in a model, you need to add this as a variable in the class:
protected $connection = 'mysql_auth';
Now, by default the model queries will do queries to that exact connection.
Just as a note, to build migrations, use Schema::connection('mysql_auth')->create(...).
Different hashing method:
Original:
To use different hashing functionality, you need to, basically, use a different class as a Hash class.
By default, hashing, as defined in providers, is done here: Illuminate\Hashing\HashServiceProvider::class. To change it, you'll have to create a separate, different class as a provider and change this line:
$this->app->singleton('hash', function () {
return new BcryptHasher;
});
Now, this will then link to your hashing class (that will implement HasherContract interface) that will do the sha512 (or whatever else) hashing.
All in all, check out Illuminate\Hashing\HashServiceProvider, how it registers the hashing methods and Illuminate\Hashing\BcryptHasher for the methods that you need to implement to implement your hashing.
Update:
Comment out Illuminate\Hashing\HashServiceProvider::class in providers and add something like \App\Providers\NewHashServiceProvider::class. Now, we create a new provider(app/Providers). This should work:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class NewHashServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('hash', function () {
return new \App\ShaHasher;
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['hash'];
}
}
This actually returns our hasher, that we will create in a moment.
To implement ShaHasher, create a class that implements HasherContract (just like BcryptHasher does):
<?php
namespace App;
use RuntimeException;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class ShaHasher implements HasherContract
{
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*
* @throws \RuntimeException
*/
public function make($value, array $options = [])
{
return hash('sha512',$value);
}
/**
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
{
if (strlen($hashedValue) === 0) {
return false;
}
return hash('sha512',$value) == $hashedValue
}
/**
* Check if the given hash has been hashed using the given options.
*
* @param string $hashedValue
* @param array $options
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
{
return false;
}
}