相关疑难解决方法(0)

Symfony2创建自己的编码器来存储密码

我是Symfony2的新手,我可能有一个关于在我的数据库中编码用户密码的简单问题.

我想以这种方式编码并在DB中存储我的用户密码:

encoded_password = salt . sha1 ( salt . raw_password )
Run Code Online (Sandbox Code Playgroud)

我发现了各种编码器(sha1,sha512,明文),我在我的数据库raw_password {salt}中看到了明文,但我仍然不满意Symfony2中的signin/login/getSalt()方法.

如果你可以给我一个提升(请假设我不想使用现有的用户管理包,我想自己制作)这将是真棒!

谢谢

编辑:

我可以在我的signinAction()中做到这一点:

$salt = substr(md5(time()),0,10);
$pwd = $encoder->encodePassword($user->getPassword(), $salt);
$user->setPassword($salt.$pwd);
Run Code Online (Sandbox Code Playgroud)

我可以在我的getSalt()中做到这一点:

return substr($this->password,0,10);
Run Code Online (Sandbox Code Playgroud)

但我目前只有我的loginAction():(见这里:http://symfony.com/doc/current/book/security.html )

// src/Acme/SecurityBundle/Controller/Main;
namespace Acme\SecurityBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;

class SecurityController extends Controller
{
    public function loginAction()
    {
        $request = $this->getRequest();
        $session = $request->getSession();

        // get the login error if there is one
        if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        }

        return $this->render('AcmeSecurityBundle:Security:login.html.twig', …
Run Code Online (Sandbox Code Playgroud)

php security hash symfony

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

hash ×1

php ×1

security ×1

symfony ×1