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 ...
随机推荐
- asp.net乱码问题
1.html文件乱码 html文件是有编码方式的,比如"UTF-8"."GB2312". A.VS中在文件选项,文件另存为...,保存右边的下拉框编码保存... ...
- vant - 弹框 【Popup 弹出层】【DatetimePicker 时间选择】
[HelloWorld.vue] <template> <div class="hello"> <van-row class="m-head ...
- 将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct
https://groups.google.com/forum/#!topic/golang-nuts/JkvR4dQy9t4 https://golang.org/misc/cgo/gmp/gmp. ...
- drf频率组件
1.简介 控制访问频率的组件 2.使用 手写一个自定义频率组件 import time #频率限制 #自定义频率组件,return True则可以访问,return False则不能访问 class ...
- yarn client中的一个BUG的修复
org.apache.spark.deploy.yarn.Client.scala中的monitorApplication方法: /** * Report the state of an applic ...
- 创建vue项目的时候遇到:PhantomJS not found on PATH
1.提示找不到PhantomJS需要进行下载,如果网速允许的话可以直接 npm install -g phantomjs 如果网速不给力的话,那就先进行淘宝镜像安装 npm install -g cn ...
- [LeetCode] 584. Find Customer Referee_Easy tag: SQL
Given a table customer holding customers information and the referee. +------+------+-----------+ | ...
- js 的date的format时间,获取当前时间,前一天的日期
Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...
- svn ignore 的用法
一个很简单的需求,我想在add一个文件时忽略里面某种格式的文件,怎么弄? 选中文件夹,然后tortoiseSvn->setting-> global ignore pattern:是客户端 ...
- React/VUE 脚手架2.0和3.0
react官方脚手架 npm install -g create-react-app create-react-app my-app cd my-app npm start 区别自己对比 vue2.x ...