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 ...
随机推荐
- 基于TensorFlow的简单验证码识别
TensorFlow 可以用来实现验证码识别的过程,这里识别的验证码是图形验证码,首先用标注好的数据来训练一个模型,然后再用模型来实现这个验证码的识别. 生成验证码 首先生成验证码,这里使用 Pyth ...
- 【剑指offer】把数组排成最小的数
一.题目: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. 二.思路: ...
- PHP 生成器入门
https://juejin.im/entry/5b4c2d76f265da0f697029ad PHP 在 5.5 版本中引入了「生成器(Generator)」特性,不过这个特性并没有引起人们的注意 ...
- 自己实现strtok函数
思路:每次在原来字符串中查找分隔字符串,将分隔字符串中所有字符设为'\0',然后输出分隔串前的子串,同时更新原串的起始位置. PS:有不少博客作者自己实现的方法中往往只将分隔串当做一个字符,实际上可以 ...
- C++中为何大量使用类指针
C++的精髓之一就是多态性,只有指针或者引用可以达到多态.对象不行类指针的优点: 第一实现多态. 第二,在函数调用,传指针参数.不管你的对象或结构参数多么庞大,你用指针,传过去的就是4个字节.如果用对 ...
- sap 类的左侧导航栏
- 118A
#include <iostream> #include <cctype> #include <string> using namespace std; int m ...
- 删除 clean tomcat7:run
1.在eclipse中运行的绿色箭头旁边有个下箭头,点击: 2.选择Run Configurations... 3.在Maven Builder下删除不想要的
- 19-Python3 函数
def area(width,heigh): return width*heigh def print_wecome(name): print('welcome',name) print('Runoo ...
- java json Gson
引入 Gson 到 pom.xml <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <de ...