Symfony2 UserSecurityEncoder实现自己的验证方式
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实现自己的验证方式的更多相关文章
- C# 中参数验证方式的演变
一般在写方法的时候,第一步就是进行参数验证,这也体现了编码者的细心和缜密,但是在很多时候这个过程很枯燥和乏味,比如在拿到一个API设计文档的时候,通常会规定类型参数是否允许为空,如果是字符可能有长度限 ...
- SQLSERVER误删除了Windows登录用户验证方式使用Windows身份验证的解决方法
SQLSERVER误删Windows登录用户验证方式使用Windows身份验证的解决方法 今天看到这篇文章:没有了SA密码,无法Windows集成身份登录,DBA怎么办? 想起来之前着急哥问我的一个问 ...
- 两系统用asp.net forms 身份验证方式实现跨域登录信息共享
1.两个系统的 web.config 都配置为 forms 验证方式( system.web —> authentication 节点) 2.在两个系统的Web.config里配置相同的 sys ...
- Azure Service Bus 中的身份验证方式 Shared Access Signature
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)
最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...
- Asp.net Mvc4 基于Authorize实现的模块权限验证方式
在MVC中,我们可以通过在action或者controller上设置Authorize[Role="xxx"] 的方式来设置用户对action的访问权限.显然,这样并不能满足我们的 ...
- Webservice加上SoapHeader验证方式
提供一种基于SoapHeader的自定义验证方式,代码如下: public class MySoapHeader : System.Web.Services.Protocols.SoapHeader ...
- IIS下的身份验证方式管理
设置.查看身份验证方式 #导航到某站点下: cd IIS:\Sites\DemoSite\DemoApp #启用站点test01下的Windows身份验证 Set-WebConfigurationPr ...
- asp.net中常用的几种身份验证方式
转载:http://www.cnblogs.com/dinglang/archive/2012/06/03/2532664.html 前言 在B/S系统开发中,经常需要使用"身份验证&q ...
随机推荐
- finecms如何控制调用子栏目的数量
finecms如何控制调用子栏目的数量?比如只要调用栏目id为23下的3个子栏目要怎么写?我们把num=3放后面不能实现,放在return前面就可以了,原来是顺序的问题,return只能放最后 {li ...
- 报错解决——linux下执行sh出现异常"syntax error: unexpected end of file"
有时我们在linux下执行一个sh文件,会报错“SYNTAX ERROR:UNEXPECTED END OF FILE”,这个现象主要是工作的系统环境改变造成的. 若最初脚本中是在windows下,使 ...
- vuex操作
import Vuex from 'vuex' //引入Vue.use(Vuex) //加载到Vue中//创建一个数据存储对象var store=new Vuex.Store({ //state可以当 ...
- MYSQL PROCEDURE 测试用例
/** * 查询俱协信息 */ DROP PROCEDURE IF EXISTS `get_club_list`; DELIMITER $$ CREATE PROCEDURE `get_club_li ...
- pycharm的安装和使用
python开发IDE: pycharm.eclipse 1.要专业版 2.不要汉化版 一.运算符 + - * ./ ** % // 判断某个东西是否在东西里面包含 in not ...
- BBS项目
一.需求分析 1.首页(显示文章) 文章详情 点赞,点踩 文章评论(子评论,评论的展示) 登录功能(图片验证码) 注册功能(基于form验证,ajax) 个人站点(不同人不同样式,文章过滤) 后台管理 ...
- IOP知识点(5)
1 检验规则 取“或” 2 IOP升级中心 2 IOP升级中心 http://10.110.17.12:8080/cloud-ops/#/environment/ admin 我修改了io ...
- maxcompute笔记
maxcompute安装和配置 https://help.aliyun.com/document_detail/27804.html?spm=a2c4g.11174283.3.5.566a590e0P ...
- [LeetCode] 35. Search Insert Position_Easy tag: Binary Search
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- 使用JWT的RSA256加密做为用户认证, 测试性能
http://www.giantflyingsaucer.com/blog/?p=5994 使用JWT的token认证,防止别人知道了接口后,随意调用,但是发现 stepping : 4 microc ...