我正在为一款游戏开发一个名为AAC(自动帐号创建器)的网站,它基本上是一个为玩家创建帐号、玩家和其他一些东西的网站.服务器只支持SHA1和plain,这是完全不安全的.我无法深入了解源代码并进行更改.如果有什么方法可以使用SHA1,我将不胜感激.我刚刚读到了BCrypt,它很棒,但我无法真正更改源代码以适应BCrypt.我设法让SHA1注册如下:

$password = $input['password'];
$password = sha1($password);

But I simply can't login. am I doing it wrong? seems like Laravel won't let me login.

我有get_registerpost_register,还有get_loginpost_login.我是否需要更改post_登录中的某些内容以使其登录?

I'm using Laravel's php server (php artisan serve) and phpMyAdmin on WAMP. I think Laravel checks when you are checking the DB via the Auth::attempt method laravel is doing some form of hashing to check the current pw and the logged in one to check against each other.

推荐答案

You'll have to rewrite the Hash module. Thanks to Laravel's ideas of following IoC and Dependency Injection concepts, it'll be relatively easy.

First, create a app/libraries folder and add it to composer's autoload.classmap:

"autoload": {
    "classmap": [
        // ...

        "app/libraries"
    ]
},

Now, it's time we create our class. Create a SHAHasher class, implementing Illuminate\Hashing\HasherInterface. We'll need to implement its 3 methods: make, check and needsRehash.

Note: On Laravel 5, implement Illuminate/Contracts/Hashing/Hasher instead of Illuminate\Hashing\HasherInterface.

app/libraries/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;
    }

}

Now that we have our class done, we want it to be used by default, by Laravel. To do so, we'll create SHAHashServiceProvider, extending Illuminate\Support\ServiceProvider, and register it as the hash component:

app/libraries/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');
    }

}

Cool, now all we have to do is make sure our app loads the correct service provider. On app/config/app.php, under providers, remove the following line:

'Illuminate\Hashing\HashServiceProvider',

然后,添加以下内容:

'SHAHashServiceProvider',

Laravel相关问答推荐

我是否需要/是否可以从控制器运行LARLAVEL备份?

如何在 laravel 5.3 中验证没有 auth:api 中间件的用户?

Laravel 有Many Many to Many To One Eloquent

安卓 retrofit |发布自定义对象(将 json 发送到服务器)

Laravel belongsToMany 关系在两个表上定义本地键

允许的内存大小 134217728 字节用尽(试图分配 20480 字节) Laravel

调用未定义的函数 App\Http\Controllers\ [函数名]

这个上下文的流程应该是怎样的? (根据 Select 的付款方式,将处理付款的代码放在哪里?)

在 Laravel 中下载后如何重定向?

计算laravel中查询返回的行数

如何在 AWS Elastic Beanstalk 上设置和使用 Laravel 调度?

何时在 Laravel 中使用 Repository vs Service vs Trait?

Laravel 分页方法不适用于 map 集合?

扩展模型 == 扩展 Eloquent?

Laravel 迁移命名约定

安装后在 Lumen 中找不到页面

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

Laravel 隐藏属性.例如密码 - 安全

复合唯一密钥验证 - laravel

Laravel 5如何获取路由动作名称?