Reputation: 1668
I have to generate a string using the email id and current date.
This is for the purpose of providing an encrypted key to the user at the time of forgot password.
How can I generate this?
Upvotes: 1
Views: 696
Reputation: 9
You can generate string in Codigniter by using "encryption_key" in config file. 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 = "[email protected]";
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.
Result will be something like this
efc080b13a0fc4d1d220c5dcecd87479eca3a2872fa349f0bbf7827a6652ba870bf1b877f83d3f81e33aa8ae8634d97696864224cbfba14c0a3ca2edb50205c4axQjvBYx93dTrN0ZBiJLQcAu+WzFmdIyMYqwxwkRyIlYvCOIRO4Qgec9Nz8Ds1Kn (encrypted form)
[email protected]/11/13 (decrypted form)
I hope all this will help you a lot.
Upvotes: 0
Reputation: 117
i can't say this is the right thing, but you can try this
<?php
$this->load->library('encrypt');
$email = "[email protected]";
$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);
?>
Upvotes: 1