我已在codeigniter中为登录页面输入了代码,其中输入了用户名和密码。单击“提交”按钮后,将从数据库中选择密码并进行解码,但解密的密码不是原始密码。
显示另一个带有各种符号的密码,但不显示原始密码。
$this->encrypt->decode($row['password'], ENC_KEY)
未提供原始密码。我在配置文件中设置了encryption_key
,并且还称为库加密。
但仍然是解码功能没有显示原始密码。为什么会那样?
我已将控制器文件中的构造函数指定为:
public function __construct()
{
parent::__construct();
$this->load->library('encrypt');
$this->load->library('session');
$this->load->model("loginmodel");
}
答案 0 :(得分:0)
希望这会对您有所帮助:
使用配置加密密钥第一种方式
使用$this->config->item('encryption_key'
)获取配置加密密钥
$msg = 'password';
$key = $this->config->item('encryption_key');
$encrypted_data = $this->encrypt->encode($msg,$key);
echo $encrypted_data.PHP_EOL;
$original = $this->encrypt->decode($encrypted_data,$key);
echo $original;
第二:如果您不想使用配置加密密钥,请使用自己的密钥
$msg = 'password';
$key = 'mykey';
$encrypted_data = $this->encrypt->encode($msg,$key);
echo $encrypted_data.PHP_EOL;
$original = $this->encrypt->decode($encrypted_data,$key);
echo $original;
更多信息:https://www.codeigniter.com/user_guide/libraries/encrypt.html