gpt4 book ai didi

php - 什么是用于从数据库获取用户的正确 security.yml 文件

转载 作者:行者123 更新时间:2023-11-30 22:55:24 24 4
gpt4 key购买 nike

我的 security.yml 文件有一些问题:

# you can read more about security in the related section of the documentation
# http://symfony.com/doc/current/book/security.html
security:
# http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
encoders:
#Symfony\Component\Security\Core\User\User: plaintext
Login\Loginbundle\Entity\User: sha512

# http://symfony.com/doc/current/book/security.html#hierarchical-roles
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
users:
entity: { class: LoginLoginBundle:User, property: username }
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

# the main part of the security, where you can set up firewalls
# for specific sections of your app
firewalls:
secured_area:
pattern: ^/

anonymous: ~
form_login:
provider: users
login_path: login
check_path: login_check
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

我有一个带有登录表单的网站。用户位于数据库中。我可以使用用户名:user 和密码:userpass 登录,但我怎样才能让它与数据库中的用户一起使用?

我已经阅读了有关 UserInterfaces 的内容并尝试使用它,但没有成功。

也许用户实体有帮助,这里是:

<?php

namespace Login\LoginBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* User
*/
class User implements UserInterface, \Serializable
{
/**
* @var string
*/
private $username;

/**
* @var string
*/
private $email;

/**
* @var string
*/
private $password;

/**
* @var integer
*/
private $money;

/**
* @var integer
*/
private $userid;

/**
* @var \Login\LoginBundle\Entity\Team
*/
private $teamTeamid;

/**
* @inheritDoc
*/
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}

/**
* @inheritDoc
*/
public function getRoles()
{
return array('ROLE_USER');
}

/**
* @inheritDoc
*/
public function eraseCredentials()
{
}

/**
* @see \Serializable::serialize()
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}

/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}

/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;

return $this;
}



/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}

/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;

return $this;
}

/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}

/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;

return $this;
}

/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}

/**
* Set money
*
* @param integer $money
* @return User
*/
public function setMoney($money)
{
$this->money = $money;

return $this;
}

/**
* Get money
*
* @return integer
*/
public function getMoney()
{
return $this->money;
}

/**
* Get userid
*
* @return integer
*/
public function getUserid()
{
return $this->userid;
}

/**
* Set teamTeamid
*
* @param \Login\LoginBundle\Entity\Team $teamTeamid
* @return User
*/
public function setTeamTeamid(\Login\LoginBundle\Entity\Team $teamTeamid = null)
{
$this->teamTeamid = $teamTeamid;

return $this;
}

/**
* Get teamTeamid
*
* @return \Login\LoginBundle\Entity\Team
*/
public function getTeamTeamid()
{
return $this->teamTeamid;
}
}

编辑 security.yml 文件和访问数据库用户的正确方法是什么?

最佳答案

您是否尝试使用数据库中的用户登录?

如果您尝试使用名称“user”登录并传递“userpass”,这应该有效。

如果您想使用数据库中的用户,您应该像这样编辑您的 security.yml 文件

providers:
user:
entity:
class: Login\LoginBundle\Entity\User
property: username

关于php - 什么是用于从数据库获取用户的正确 security.yml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26619011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com