如何将CodeIgniter用户密码移动到Laravel [英] How to move CodeIgniter user passwords to Laravel

查看:152
本文介绍了如何将CodeIgniter用户密码移动到Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CI项目,并希望将其数据库迁移到Laravel的一个。

I have a CI project and want to migrate its database to the Laravel's one.

唯一的问题是,他们有不同的哈希用户密码的方式,所以我无法找到将它们从一个数据库移动到另一个数据库的方法。

The only problem is that they have different ways of hashing user passwords and so I cannot find a way to move them from one database to another.

我已经搜索了答案,但没有人发现有关迁移密码的问题。

I have already googled for the answer but nobody I found speaks about migrating passwords.

提前感谢。

推荐答案

我没有CodeIgniter的经验,它会进行密码哈希,但这里是我将如何处理这个问题。

I have no experience with CodeIgniter and don't know how it does password hashing, but here's how I would approach the problem.

要清楚一点:你只能转换密码到Laravel哈希如果你有实际密码(纯文本)。由于您不存储普通密码,因此您只在用户登录时输入密码。

To make something clear: You can only "convert" the password to a Laravel hash if you have the actual password (in plain text). As you don't store the plain password you only have it at the moment the user logs in our enters the password somewhere.

因此,您必须意识到此迁移是几个小时后就完成了。

Therefore you have to realize that this migration isn't done in a few hours. It will take some time for all your users to enter their passwords.

所以我得到的是你应该在你的用户表中为CodeIgniter密码添加一个字段。让我们把它叫做 ci_password 。 (或者您可能只需要将旧密码列重命名为此密码并为Laravel密码创建一个新密码)。

So what I'm getting at is you should add a field to your users table for the CodeIgniter password. Let's call it ci_password. (Or probably you just have to rename the old password column to this and create a new one for the Laravel password).

现在每次用户登录时,检查Laravel密码是否存储在数据库中并尝试登录。如果没有存储Laravel哈希值,请使用 ci_password 检查。 (为此,你必须在你的Laravel应用程序中使CodeIgniters哈希工作。对不起,不能帮助你)

Now every time a user logs in, you first check if a Laravel password is stored in the database and attempt a log in. If there is no Laravel hash stored, check with the ci_password. (For this you will have to make CodeIgniters hashing work inside your Laravel application. Sorry can't help you with that)

如果 ci_password 有效使用从用户输入的密码并生成Laravel哈希(使用 Hash :: make('secret'))。将新的哈希存储在数据库中,并删除($ NULL ci_password

If the ci_password is valid use the password input from the user and generate the Laravel hash (using Hash::make('secret')). Store the new hash in the database and delete (set to NULL) the ci_password.

这样,密码将逐个迁移,您不得不做任何事情。也许,在一个幸运的日子,所有旧的哈希将被迁移,你可以删除这个逻辑和数据库中的列。

This way the passwords will be migrated one by one and you have to do nothing. And maybe, on one lucky day, all old hashes will be migrated and you can remove this logic and the column in the database.

这篇关于如何将CodeIgniter用户密码移动到Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆