Php 使用Symfony 3中已有的数据库登录
我试图在我最新的Symfony应用程序中设置一个表单流程。我遵循Symfony的食谱,但没有成功 我想使用一个预先存在的数据库,其中loginUtil和passUtil字段是我的连接要求 因此,我将security.yml文件设置为:Php 使用Symfony 3中已有的数据库登录,php,symfony,Php,Symfony,我试图在我最新的Symfony应用程序中设置一个表单流程。我遵循Symfony的食谱,但没有成功 我想使用一个预先存在的数据库,其中loginUtil和passUtil字段是我的连接要求 因此,我将security.yml文件设置为: security: providers: main: entity: Customer\CustomerBundle\Entity\utilisateur property: loginUti
security:
providers:
main:
entity: Customer\CustomerBundle\Entity\utilisateur
property: loginUtil
encoders:
Customer\CustomerBundle\Entity\utilisateur:
algorithm: sha1
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
provider: main
form_login:
login_path: /login
check_path: /login_check
logout:
path: /logout
target: home_page
根据文档设置实现接口UserInterface的实体
<?php
namespace Customer\CustomerdBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* utilisateur
*
* @ORM\Table(name="utilisateur")
* @ORM\Entity(repositoryClass="Customer\CustomerdBundle\Repository\utilisateurRepository")
*/
class utilisateur implements UserInterface
{
private $username;
private $password;
private $salt;
private $roles;
// declaration of other fields from pre existing database
// setters and getters
// ...
//
public function getRoles()
{
return $this->roles;
}
public function getPassword()
{
$this->password = $this->getPassUtil();
return $this->password;
}
public function getsalt()
{
return $this->salt;
}
public function getusername()
{
return $this->username = $this->getLoginUtil();
}
public function eraseCredentials()
{
}
}
?>
以及我的身份验证表:
{% extends "CustomerCustomerBundle::layout.html.twig" %}
{% block maincontentFormLogin %}
<form action="{{ path('login_check') }}" method="post">
<label for="username">Login :</label>
<input type="text" id="username" name="_username" value="" />
<br />
<label for="password">Mot de passe :</label>
<input type="password" id="password" name="_password" />
<br />
<input type="submit" value="Connexion" />
</form>
{% endblock %}
{%extends“CustomerCustomerBundle::layout.html.twig”%}
{%block maincontentFormLogin%}
登录:
路况:
{%endblock%}
我在/var/logs/dev.log
中看到,我的用户名提交正确,请求时使用的是条令,而不是密码,他是空的。所以从逻辑上讲,我的证书是坏的
任何人都可以让我知道我做错了什么?我终于找到了解决办法 我现在不明白为什么。我需要在编码器部分中添加somme参数,如下所示:
encoders:
Customer\CustomerBundle\Entity\utilisateur:
algorithm: sha1
encode_as_base64: false
iterations: 1
我现在需要记录我自己,以了解原因
谢谢你们 您的登录检查控制器是什么样子?@Brent抱歉,问题更新了thxb默认情况下,大多数密码编码器实际上会循环数百次甚至数千次对密码进行编码,以确保更安全的哈希。您现有的数据库只使用了一个。
{% extends "CustomerCustomerBundle::layout.html.twig" %}
{% block maincontentFormLogin %}
<form action="{{ path('login_check') }}" method="post">
<label for="username">Login :</label>
<input type="text" id="username" name="_username" value="" />
<br />
<label for="password">Mot de passe :</label>
<input type="password" id="password" name="_password" />
<br />
<input type="submit" value="Connexion" />
</form>
{% endblock %}
encoders:
Customer\CustomerBundle\Entity\utilisateur:
algorithm: sha1
encode_as_base64: false
iterations: 1