Codeigniter无法解码加密的密码 [英] Codeigniter cannot decode the encrypted password

查看:204
本文介绍了Codeigniter无法解码加密的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个登录表单,用户提交其用户名和密码。如果用户名存在,我解码密码,并检查是否与提交的密码相同。

I made a login form where the user submit his username and password. If the username exist I decode the password and check if is the same as the submitted password.

//这是来自db

string(50) "v+bNPHNWHGQbcxrvu1vN8Ty++cMq0oEeaZesvfCfsLgNAFgZno"

//这是解码之后的字符

// And this is after decode the string above

string(32) "�� U�U{q�0�4��è€UC��o�/�*�."

但它应该返回 123456

对于encode我使用

For encode I use

$this->encrypt->encode('123456');

这是秘密密钥

$config['encryption_key'] = 'kRlaMneym7rF';

//编辑

该密码字段设置为varchar 50

The problem was that password field was set to varchar 50

推荐答案

请在config中检查您的代码字符集

Please check your codeigniter charset in config

$config['charset'] = 'UTF-8';

与数据库的字符集。你的冲突可能来自那里。

versus the charset of your database. Your conflict is probably coming from there.

使用Codeigniter进行测试,看看它是否返回正确的结果。尝试像以前的硬编码,或复制和测试这在你的控制器。

Put Codeigniter to test and see if it return the right result. Try hard-coding like before or copy and test this in your controller.

function testencrypting(){
  $str = '12345';
  $key = 'my-secret-key';
  $encrypted = $this->encrypt->encode($str, $key);
  echo $this->encrypt->decode($encrypted, $key);
  exit;

}

:12345.如果这样工作,那么你的问题可能是CHARACTER SET(CHARSET)。我在这里使用加密密钥。

Mine produce the expected result: 12345. If that works, then your problem is possibly CHARACTER SET (CHARSET). I'm using an encryption key here. You could use the default in config by leaving out the second parameter in encode and decode.

让我知道是否有帮助

这篇关于Codeigniter无法解码加密的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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