您将不得不重写该
Hash模块。感谢Laravel遵循IoC和依赖注入概念的想法,这将相对容易。
首先,创建一个
app/libraries文件夹并将其添加到作曲家的文件夹中
autoload.classmap:
"autoload": { "classmap": [ // ... "app/libraries" ]},现在,该创建类了。创建一个
SHAHasher类,实现
IlluminateHashingHasherInterface。我们需要实现它的3种方法:
make,
check和
needsRehash。
注意: 在Laravel
5上,实现
Illuminate/Contracts/Hashing/Hasher而不是
IlluminateHashingHasherInterface。
app / libraries / SHAHasher.php
class SHAHasher implements IlluminateHashingHasherInterface { public function make($value, array $options = array()) { return hash('sha1', $value); } public function check($value, $hashedValue, array $options = array()) { return $this->make($value) === $hashedValue; } public function needsRehash($hashedValue, array $options = array()) { return false; }}现在我们完成了类,我们希望Laravel在默认情况下使用它。为此,我们将创建
SHAHashServiceProvider,扩展
IlluminateSupportServiceProvider并将其注册为
hash组件:
app / libraries / SHAHashServiceProvider.php
class SHAHashServiceProvider extends IlluminateSupportServiceProvider { public function register() { $this->app['hash'] = $this->app->share(function () { return new SHAHasher(); }); } public function provides() { return array('hash'); }}太酷了,现在我们要做的就是确保我们的应用加载了正确的服务提供商。在
app/config/app.php下方的上
providers,删除以下行:
'IlluminateHashingHashServiceProvider',
然后,添加以下内容:
'SHAHashServiceProvider',



