drtsd7864 2014-12-13 18:24
浏览 22
已采纳

Codeigniter - 使用加密库登录

I have created a signup form using the codeigniter encryption library to store the users passwords as follow:

$encrypted_password = $this->encrypt->encode($this->input->post('password')); 

I have notice that each time we encrypt (event if we encrypt the same password) the encryption function it produce a different output.

My question is the follow: What is the best way to compare the two encrypted passwords when the user try to login on the system as we know that each time we encrypt we get a different encrypted string?

  • 写回答

1条回答 默认 最新

  • douba4933 2014-12-13 19:10
    关注

    Look here: https://ellislab.com/codeigniter/user-guide/libraries/encryption.html

    $encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
    
    $plaintext_string = $this->encrypt->decode($encrypted_string);
    

    The encription class is using the symetric encoding. So to compare you have to decrypt the password and compare it. If you want to use a one way method use hashing, Correct me if I'm wrong but codeigniter supports only up to sha1, so maybe look here for what native php has to offer: http://php.net/manual/en/function.hash.php

    You could also combine both methods, hash and than encrypt.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么