簡體   English   中英

FOSUserBundle 不斷將密碼保存為明文

[英]FOSUserBundle keeps saving passwords as plaintext

我已經在 Symfony 3.4 應用程序中安裝了 FOSUserBundle,目的是最終將它與 LexikJWTAuthenticationBundle 一起使用來創建 API。 我的security.yml文件如下所示:

security:

    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:

        login:
            pattern:  ^/api/login
            stateless: true
            anonymous: true
            json_login:
                check_path:               /api/login_check
                success_handler:          lexik_jwt_authentication.handler.authentication_success
                failure_handler:          lexik_jwt_authentication.handler.authentication_failure

        api:
            pattern:   ^/api
            stateless: true
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

    access_control:
        - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }

...而我的 User 類如下所示:

<?php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

出於某種原因,當我使用 Doctrine 的設備包創建和持久化測試用戶時,數據庫中的 fos_user 表以明文形式顯示新用戶的密碼——不理想!

我已經在我的 mac 上完成了brew install bcrypt以確保我安裝了所需的依賴項,但這沒有幫助。 有誰知道這是怎么回事?

看起來問題僅在我嘗試在裝置中加載用戶時才存在。 如果我使用 bin/console fos:user:create,則會正確創建用戶。

因此,假設有一種方法可以非交互式地運行該命令,我想我將添加一個 Make 命令,該命令在加載設備時多次調用該 Symfony 控制台命令。

盡管如此,我還是有興趣聽聽其他人對此的看法。

哦,我想你在燈具中使用 $user->setPassword("pass123") ,對嗎? Doctrine 不知道密碼是什么,因此將其作為明文處理。 您應該使用 UserPasswordEncoderInterfaces encodePassword。 文檔在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM