迁移旧用户的Symfony2 [英] Migrating legacy users to symfony2
问题描述
我从前pressionengine移动到Symfony2的,我期待为迁移的用户密码的最佳方式。的目标是让旧有用户与他们现有的凭证登录,而对新的用户口令创建的默认方式。
I'm moving from expressionengine to symfony2 and I'm looking for the best way to migrate the user passwords. The goal is to let legacy users log in with their existing credentials, while passwords for new users are created the default way.
我看过自定义身份验证提供者和自定义用户提供商和思考阉羊还是不来为旧有用户的一个单独的实体,但我不知道什么了是最好的方式/设计上面实现。
I have looked at custom authentication providers and custom user providers and thought about wether or not to create a separate entity for the legacy users, but I don't know what'd be the best way/design to achieve the above.
FYI:
- 据我所看到的,当然pressionengine只是对密码进行加密
使用SHA1,仅此而已。 - 我目前使用的FOSUserBundle。
谁能指点我一个解决方案?
Can anyone advice me on a solution?
推荐答案
想通了!
创建自定义的连接codeR和使用FOSAdvancedEn codeR束来选择合适的EN codeR。
Create a custom encoder and use FOSAdvancedEncoder bundle to select the appropriate encoder.
1。创建连接codeR
<?php
namespace Acme\MyBundle\Security\Encoder;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
class LegacyEncoder implements PasswordEncoderInterface {
public function encodePassword($raw, $salt)
{
// Your Custom encoder logic
return $something
}
public function isPasswordValid($encoded, $raw, $salt)
{
return $encoded === $this->encodePassword($raw, $salt);
}
}
2。注册您的EN codeR为服务
services:
acme.legacy_encoder:
class: Acme\MyBundle\Security\Encoder\LegacyEncoder
3。安装FOSAdvancedEn coderBundle
看看这里:<一href=\"https://github.com/friendsofsymfony/FOSAdvancedEn$c$crBundle/blob/master/Resources/doc/index.md\">https://github.com/friendsofsymfony/FOSAdvancedEn$c$crBundle/blob/master/Resources/doc/index.md
4。配置您的EN codeRS
在应用程序/ config.yml
:
fos_advanced_encoder:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
legacy_encoder:
id: acme.legacy_encoder
5。实施EN codeR意识到界面User类
use FOS\AdvancedEncoderBundle\Security\Encoder\EncoderAwareInterface;
use FOS\UserBundle\Entity\User as BaseUser;
class User extends BaseUser implements EncoderAwareInterface {
...
public function getEncoderName() {
if($this->islegacy()) {
return "legacy_encoder";
}
return NULL;
}
}
记住要添加一个布尔字段来管理,如果用户是一个传统用户或没有。
Remember to add a boolean field to administer if a user is a legacy user or not.
这就是它。
这篇关于迁移旧用户的Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!