Symfony2,从数据库登录返回负载用户' Bad Credentials'

时间:2014-04-25 17:24:16

标签: security symfony login

目前我的智慧已经结束了这个过程。我一直在跟踪Symfony's tutorial从数据库加载用户并且没有让它正常工作。

我的security.yml:
http://pastebin.com/cczdxxqG

user.php的:
http://pastebin.com/Yh53bXp6

UserRepository.php:
http://pastebin.com/6pL6uYQW

Role.php:
http://pastebin.com/G5RnxHDi

SecurityController.php:
http://pastebin.com/ynZgPfSj

登录表单的Twig模板:

<form action="{{ path('login_check') }}" method="post" class="login">

    <label for="username">Username:</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" /><br />

    <label for="password">Password:</label>
    <input type="password" id="password" name="_password" /><br />

    {#
        If you want to control the URL the user
        is redirected to on success (more details below)
        <input type="hidden" name="_target_path" value="/account" />
    #}

    <input type="hidden" name="_csrf_token"
        value="{{ csrf_token('authenticate') }}">

    <button type="submit">login</button>
</form>

当我使用用户名登录时:admin和密码:adminpass它工作正常,但它不会从数据库加载用户。我做错了什么?

2 个答案:

答案 0 :(得分:1)

我认为问题出在你的security.yml中,它无法识别你的自定义用户提供者,将其改为如下所示

providers:
    chain_provider:
        chain:
            providers: [in_memory, user_db]
    in_memory:
        memory:
            users:
                admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
    user_db:
        entity: { class: Bundle:User }

因为您有自定义用户提供商,所以您不需要通过property: username 另一方面,如果您的包名称为CIRBundleBundle

,我不确定您的包名称

希望这会有所帮助

答案 1 :(得分:0)

检查数据库表中的列密码。也许它太短了。将它修改为VARCHAR(100)或200