CodeIgniter Forums
Encryption and validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Encryption and validation (/showthread.php?tid=81508)



Encryption and validation - sprhld - 03-13-2022

Hello!

My new learning is encryption. But I got some curios results regarding validate data before store:

This is my validation rule for a specific field:

PHP Code:
'number'  => 'required|decimal|trim'

And this is the code how I decode it. I use a own helper decode() to do so, because this helper I can use everywhere and I don't have to load it on serveral points in my app. Data is from a from.

PHP Code:
    public function add ($data)
    {
        $inserts = [
            'number' => encode($data['qm']),
        ];

        return $this->builder()->insert($inserts);
    

If I send "AAA" to the form, it will decoded stored. But this is wrong. First, AAA is not a number. But this is not checked. So It should the decoded string validated, but this isn't to. In an other case/model, I use an entity where I encode and decode, but with the same result, that the validation from the model is not used.

How to combine encryption and validation? So I want to validate and then decode and store the data.


RE: Encryption and validation - ignitedcms - 03-16-2022

Hello. are you following this:

https://www.codeigniter.com/userguide3/libraries/encryption.html?highlight=encryption