fosuserbundle默认使用sha512加密

如果要实现自己的加密方式 需要继承Symfony\Component\Security\Core\Encoder\BasePasswordEncoder

<?php

namespace Mc\AdminBundle\Security\Encoder;

use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
use Symfony\Component\SecurityCore\Exception\BadCredentialsException; class JoomlaPasswordEncoder extends BasePasswordEncoder
{
private $cost; public function __construct( $cost)
{
$cost = intval( $cost);
if( $cost < 4 || $cost > 31 )
{
throw new \InvalidArgumentException('Cost too long , it must be in the range of 4-31');
}
$this->cost = sprintf('%02d' , $cost);
} public function encodePassword( $raw , $salt = null )
{
if( $this->isPasswordTooLong($raw) )
{
throw new BadCredentialsException('Invalid password.');
}
return md5( md5( $raw ) . $salt );
} public function isPasswordValid($encoded, $raw, $salt = null)
{
if ($this->isPasswordTooLong($raw))
{
return false;
} return md5( md5( $raw).$salt) === $encoded;
}
}
然后写入service 在bundle下面的Resources/config/services.yml(或者xml)添加一个服务: mc_user.security.core.encoder:
class: Mc\AdminBundle\Security\Encoder\JoomlaPasswordEncoder
arguments: [6]
也可以在DependencyInjection/Configuration.php中添加参数: $rootNode->children()
->scalarNode('cost')->defaultValue(6)->end()
->end()
;
最后在app/config/security.yml中设置自己的加密方式 这里用户组件是FOSUserBundle: security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface:
id: mc_user.security.core.encoder
这里的id是service名 即 mc_user.encoder done

Symfony2 UserSecurityEncoder实现自己的验证方式的更多相关文章

  1. C# 中参数验证方式的演变

    一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空,如果是字符可能有长度限 ...

  2. SQLSERVER误删除了Windows登录用户验证方式使用Windows身份验证的解决方法

    SQLSERVER误删Windows登录用户验证方式使用Windows身份验证的解决方法 今天看到这篇文章:没有了SA密码,无法Windows集成身份登录,DBA怎么办? 想起来之前着急哥问我的一个问 ...

  3. 两系统用asp.net forms 身份验证方式实现跨域登录信息共享

    1.两个系统的 web.config 都配置为 forms 验证方式( system.web —> authentication 节点) 2.在两个系统的Web.config里配置相同的 sys ...

  4. Azure Service Bus 中的身份验证方式 Shared Access Signature

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  5. jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)

    最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...

  6. Asp.net Mvc4 基于Authorize实现的模块权限验证方式

    在MVC中,我们可以通过在action或者controller上设置Authorize[Role="xxx"] 的方式来设置用户对action的访问权限.显然,这样并不能满足我们的 ...

  7. Webservice加上SoapHeader验证方式

    提供一种基于SoapHeader的自定义验证方式,代码如下: public class MySoapHeader : System.Web.Services.Protocols.SoapHeader ...

  8. IIS下的身份验证方式管理

    设置.查看身份验证方式 #导航到某站点下: cd IIS:\Sites\DemoSite\DemoApp #启用站点test01下的Windows身份验证 Set-WebConfigurationPr ...

  9. asp.net中常用的几种身份验证方式

    转载:http://www.cnblogs.com/dinglang/archive/2012/06/03/2532664.html   前言 在B/S系统开发中,经常需要使用"身份验证&q ...

随机推荐

  1. Windows server 2016 支持容器 ,安装docker 搭建Ubuntu+hadoop (docker为服务器)

    一.Windows server 2016 是肯定要安装的, 关于如何启动容器功能那就是控制面板中增加与删除里面的启用了,很多地方可以百度到 二. 安装Ubuntu hadoop 等  待续 注意: ...

  2. Python创建目录

    需要包含os模块进来,使用相关函数即可实现目录的创建 1.创建目录要用到的函数: (1)os.path.exists(path) 判断一个目录是否存在 (2)os.makedirs(path) 多层创 ...

  3. mysql 解锁

    show OPEN TABLES where In_use > 0;show processlist;show status like 'Table%';show status like '%l ...

  4. vux 是基于 WeUI 和Vue(2.x)开发的移动端UI组件库,主要服务于微信页面。

    https://doc.vux.li/zh-CN/ https://vux.li/

  5. Java通过jxl读取Excel

    package com.hd.all.test.testjava; import java.io.File; import java.io.IOException; import java.util. ...

  6. sklearn.svm.LinearSVC文档学习

    https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html#sklearn.svm.LinearSVC 1 ...

  7. 2018-2019-1 20189221《Linux内核原理与分析》第四周作业

    2018-2019-1 20189221<Linux内核原理与分析>第四周作业 教材学习:<庖丁解牛Linux内核分析> 第 3 章 MenuOS的构造 计算机三大法宝:存储程 ...

  8. nodejs 网上下载图片到本地,并判断图片路径是否存在

    var http = require("http"); var fs = require("fs"); var server = http.createServ ...

  9. ODS与DW之间的关系

    1.什么是数据仓库? 数据仓库是面向主题的.集成的.相对稳定的.反应历史变化的数据集合,主要用于决策支持和信息的全局共享. 时效:T+1 2.什么是ODS? ODS全称为Operational Dat ...

  10. Xgboost调参总结

    一.参数速查 参数分为三类: 通用参数:宏观函数控制. Booster参数:控制每一步的booster(tree/regression). 学习目标参数:控制训练目标的表现. 二.回归 from xg ...