[英]How to generate a string in CodeIgniter?
I have to generate a string using the email id and current date. 我必须使用电子邮件ID和当前日期生成一个字符串。
This is for the purpose of providing an encrypted key to the user at the time of forgot password. 这是为了在忘记密码时向用户提供加密密钥。
How can I generate this? 我该如何生成?
i can't say this is the right thing, but you can try this 我不能说这是对的,但是你可以尝试一下
<?php
$this->load->library('encrypt');
$email = "address@domain.com";
$date = date(Y-m-d);
$string = $email."-".$date;
$encrypted_string = $this->encrypt->encode($string);
?>
to decode the string, use this 解码字符串,使用这个
<?php
$this->load->library('encrypt');
$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
$string = $this->encrypt->decode($encrypted_string);
?>
You can generate string in Codigniter by using "encryption_key" in config file. 您可以通过在配置文件中使用“ encryption_key”在Codigniter中生成字符串。 You can easily generate encrypted string by following these steps. 您可以按照以下步骤轻松生成加密的字符串。
$config['encryption_key'] = "!@#oiqjwd2131asda3ir0000wqe+_)";
class trying extends CI_controller
{
public function index()
{
1. $this->load->library('encryption');
2. $email = "address@domain.com";
3. $date = date("Y/m/d");
4. $string = $email.$date;
5. echo $encrypted_string = $this->encryption->encrypt($string);
6. echo "<br>".$decrypt = $this->encryption->decrypt($encrypted_string);
}
}
Now when you call the controller then by default index() method will call and then on line number 5 your your concatenated values will convert into encrypted form and on line number 6 your encrypted string will convert into original form. 现在,当您调用控制器时,默认情况下将调用index()方法,然后在第5行上,您的串联值将转换为加密形式,在第6行上,您的加密字符串将转换为原始形式。
Result will be something like this 结果将是这样的
efc080b13a0fc4d1d220c5dcecd87479eca3a2872fa349f0bbf7827a6652ba870bf1b877f83d3f81e33aa8ae8634d97696864224cbfba14c0a3ca2edb50205c4axQjvBYx93dTrN0ZBiJLQcAu+WzFmdIyMYqwxwkRyIlYvCOIRO4Qgec9Nz8Ds1Kn (encrypted form)
address@domain.com2017/11/13 (decrypted form)
I hope all this will help you a lot. 希望所有这些对您有很大帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.