Welcome Guest, Not a member yet? Register   Sign In
Question about decode()
#1

[eluser]shinee[/eluser]
Hi,
I have encoded one column called 'x' in a table.
so far so good
now I am retriving the table and passing the resource called $result to the controller, I want to decode column 'x' in the model function.
How can I do it?
#2

[eluser]JoostV[/eluser]
What method did you use to encode x?
#3

[eluser]shinee[/eluser]
like this:
$msg=$input['password'];
$input['password']=$this->encrypt->encode($msg);
#4

[eluser]JoostV[/eluser]
That's in the manual, Shinee Wink $this->encrypt->decode($encrypted_string);
http://ellislab.com/codeigniter/user-gui...ption.html

As you probably know, using $this->encrypt->encode() for passwords is a security risk. It is considered good practise to encrypt passwords in such a way that they cannot be decrypted. For instance, using sha1($msg); That way, if your database is stolen, the thiefs cannot retrieve the passwords.
#5

[eluser]shinee[/eluser]
thanks,
but the issue is that I don't know how to decode only one column in the table(resource) as I wrote above
#6

[eluser]WanWizard[/eluser]
If your $resource is something returned by $query->result(), you can use
Code:
foreach ($resource as $key => $row)
{
   $resource[$key]->x = $this->encrypt->decode($row->x);
}
Just var_dump() your resource variable, see what it looks like, and write your code...
#7

[eluser]JoostV[/eluser]
Oops Wanwizard, you beat me to it Wink
#8

[eluser]shinee[/eluser]
I was trying...Smile
I am new to php so please if you can explain:
my resource come from this:
$resource=$this->db->get_where('book',array('cat'=>$name,'email'=>$email));

now you wrote:
foreach ($resource as $key => $row)
{
$resource[$key]->x = $this->encrypt->decode($row->x);
}
what is the index for this var?
$resource=$resource
x=the name of the column?
$key & $row- shuold change??
#9

[eluser]JoostV[/eluser]
I strongly advise you to read the Codeigniter userguide, especially if you're new to php Smile

Code:
// Fetch some books
$books = $this->db->get_where('book', array('cat' => $name, 'email' => $email))->result();

// For each book, decode value for column with the name 'decoded_column'
if (count($books)) {
    foreach ($books as $key => $row) {
        $books[$key]->decoded_column = $this->encrypt->decode($row->decoded_column);
    }
}
#10

[eluser]shinee[/eluser]
Thanks,
I did your example 1 on 1
I got this error
Message: Trying to get property of non-object
for this line:
$result[$key]->password = $this->encrypt->decode($row->password);




Theme © iAndrew 2016 - Forum software by © MyBB