我正在为一款游戏开发一个所谓的AAC(自动帐户创建者),它基本上是一个具有创建帐户,玩家以及为玩家提供更多功能的网站。该服务器仅支持SHA1和Plain-这是完全不安全的。我无法深入研究源代码并进行更改。如果有可以使用SHA1的信息,我将不胜感激。我刚刚阅读了BCrypt,这很棒,但是我不能真正更改源代码以适合BCrypt。我设法将SHA1这样注册:
$password = $input['password'];
$password = sha1($password);
但是我根本无法登录。我做错了吗?好像Laravel不允许我登录。
我有
get_register
和post_register
,也有get_login
和post_login
。我是否需要在post_login中进行更改以使其登录或?有什么提示吗?
我在WAMP上使用Laravel的php服务器(php artisan服务)和phpMyAdmin。我认为Laravel在通过
Auth::attempt
方法检查数据库时进行检查laravel正在某种形式的哈希检查当前pw和已登录的pw进行相互检查。 最佳答案
您必须重写Hash
模块。感谢Laravel遵循IoC和依赖注入(inject)概念的想法,这将相对容易一些。
首先,创建一个app/libraries
文件夹并将其添加到 Composer 的autoload.classmap
中:
"autoload": {
"classmap": [
// ...
"app/libraries"
]
},
现在,该创建类了。创建一个
SHAHasher
类,实现Illuminate\Hashing\HasherInterface
。我们需要实现其3种方法:make
,check
和needsRehash
。注意:在Laravel 5上,实现
Illuminate/Contracts/Hashing/Hasher
而不是Illuminate\Hashing\HasherInterface
。应用程序/库/SHAHasher.php
class SHAHasher implements Illuminate\Hashing\HasherInterface {
/**
* Hash the given value.
*
* @param string $value
* @return array $options
* @return string
*/
public function make($value, array $options = array()) {
return hash('sha1', $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 = array()) {
return $this->make($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 = array()) {
return false;
}
}
现在我们完成了类,我们希望Laravel在默认情况下使用它。为此,我们将创建
SHAHashServiceProvider
,扩展Illuminate\Support\ServiceProvider
,并将其注册为hash
组件:应用程序/库/SHAHashServiceProvider.php
class SHAHashServiceProvider extends Illuminate\Support\ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register() {
$this->app['hash'] = $this->app->share(function () {
return new SHAHasher();
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides() {
return array('hash');
}
}
太酷了,现在我们要做的就是确保我们的应用加载了正确的服务提供商。在
app/config/app.php
上的providers
下,删除以下行:'Illuminate\Hashing\HashServiceProvider',
然后,添加以下内容:
'SHAHashServiceProvider',