Php symfony2 FOSUserBundle登录返回';不良凭证';
我是FOSUserBundle的新手,几个小时以来我一直在与这个错误作斗争……在网站上找不到合适的答案 有人能帮我吗-* 这是我的子用户实体Php symfony2 FOSUserBundle登录返回';不良凭证';,php,symfony,login,fosuserbundle,Php,Symfony,Login,Fosuserbundle,我是FOSUserBundle的新手,几个小时以来我一直在与这个错误作斗争……在网站上找不到合适的答案 有人能帮我吗-* 这是我的子用户实体 <?php // src/Blogger/BlogBundle/Entity/CommonUser.php namespace Blogger\BlogBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; u
<?php
// src/Blogger/BlogBundle/Entity/CommonUser.php
namespace Blogger\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\CommonUserRepository")
* @ORM\Table(name="CommonUser")
* @ORM\HasLifecycleCallbacks
*/
class CommonUser extends BaseUser
{
/**
* @ORM\OneToMany(targetEntity="Request", mappedBy="commonUser")
*/
protected $requests;
public function __construct()
{
parent::__construct();
$this->requests = new ArrayCollection();
}
/**
* @ORM\Id
* @ORM\Column(type="integer", nullable=false)
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
...
...
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getSalt()
{
return '';
}
...
}
当您从FOSUserBundle向提供的控制器注册时,存储在DB中的密码将使用500倍SHA1和随机生成的salt进行加密。因此,如果总是通过函数getSalt()返回“”,密码将永远不会匹配不要覆盖此功能。 但是,您可以覆盖FOSUserBundle中的控制器,更多信息请参见
只需尝试更新密码。 在终端中输入:
php-fos:user:更改密码$username$password
其中,
$user
是用户名,$password
是新密码。为什么CommomUser::getSalt返回“”?添加隐藏用户未找到:在安全性下为false:。这至少会告诉您用户正在加载。
<?php
// src/Blogger/BlogBundle/Entity/Request.php
namespace Blogger\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Blogger\BlogBundle\Entity\Repository\RequestRepository;
/**
* @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\requestRepository")
* @ORM\Table(name="request")
* @ORM\HasLifecycleCallbacks
*/
class Request
{
/**
* @ORM\OneToMany(targetEntity="Note", mappedBy="request")
*/
protected $notes;
public function __construct()
{
$this->notes = new ArrayCollection();
$this->setCreated(new \DateTime());
$this->setUpdated(new \DateTime());
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="CommonUser", inversedBy="requests")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $commonUser;
/**
* @ORM\Column(type="text")
*/
protected $request;
....
....
....
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
....
....
....
}
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
public function getSalt()
{
return '';
}