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 ...
随机推荐
- Mysql聚集索引的使用
聚集索引 聚簇索引并不是一种单独的索引类型,而是一种数据存储方式(不是数据结构,而是存储结构),具体细节依赖于其实现方式,聚簇索引实际上是在同一个结构中保存了btree索引和数据行. innodb将通 ...
- select 数字/字符串/count(参数)/sum(数字) from table
第一种的写法是增加临时列,每行的列值是写在select后的数: --1select 1 from W_EC_PLACESTATION_COLLECT t--2select 2 from W_EC_PL ...
- 递归与非递归打印乘法口诀表--Scala(指令式、函数式思维练习)
object Test extends App { def printMultiTable() { var i = 1 while (i < 10) { var j = 1 while (j & ...
- 解决PHP5.6版本“No input file specified”的问题
问题描述:使用TP框架做项目时,在启用REWRITE的伪静态功能的时候,首页可以访问,但是访问其它页面的时候,就提示:“No input file specified.”原因在于使用的PHP5.6是f ...
- Nginx解析PHP的原理 | CGI、FastCGI及php-fpm的关系
Nginx解析PHP的原理,CGI/FastCGI以及PHP-Fpm的关系. 一.PHP+Nginx应运而生的场景.随着互联网的发展,用户对此接受面广,数据流的增大使得Web端的运行承载压力日益增大, ...
- [sh]md5sum接变量,find排除,sh判断文件存在
1.md5sum md5sum `cat path_to_file|dos2unix` 注: 发现有些linux是gbk编码, 导致md5或ls 接变量后报错.需要dos2unix处理 2.find排 ...
- VS Code的golang开发配置 之 代码提示
之前用VS Code的时候,发现自己的代码的提示一直不好,换用JetBrain的Goland的代码提示是好了,但是比较占用资源.在网上找了一些资料,发现很多人也是遇到第三方或者自己的代码无法提示的情况 ...
- 23个适合logo设计的常用英文字体
在很多国外的品牌中我们都会发现他们的英文字体在logo的运用中,不仅会提升logo的品质还会让logo看起来更加美观.今天我们就来看看都有哪些常常出现在logo设计中的英文字体吧. 字体,与文字本 ...
- max_execution_time with sleep
Under Linux, sleeping time is ignored, but under Windows, it counts as execution time. Note The set_ ...
- 单点登录开源架构之CAS
服务端 开源地址:https://github.com/apereo/cas Release版:https://github.com/apereo/cas/releases Windows下使用下载c ...