CodeIgniter Forums
If hashed password in entity, it is not get validate length of model validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: If hashed password in entity, it is not get validate length of model validation (/showthread.php?tid=79088)



If hashed password in entity, it is not get validate length of model validation - ipmeel - 04-18-2021

User model
PHP Code:
<?php
namespace App\Models;
use 
CodeIgniter\Model;
class 
RegisterModel extends Model
{
    protected 
$table 'users';
    protected 
$DBGroup 'user_webapp';
    protected 
$primaryKey 'id';
    protected 
$allowedFields = [
        
'email',
        
'mobile_number',
        
'password'
    
];
    protected 
$useTimestamps true;
    protected 
$validationRules = [
        
'email' => 'required|valid_email|is_unique[users.email]',
        
'password'=> 'required|min_length[8]',
    ];
    protected 
$validationMessage = [];
    protected 
$returnType    'App\Entities\RegisterEntity';
    protected 
$beforeInsert = [];


Entity class
PHP Code:
<?php
namespace App\Entities;
use 
CodeIgniter\Entity;
class 
RegisterEntity extends Entity
{
    public function 
setPassword(string $pass){
        
$this->attributes['password'] = password_hash($passPASSWORD_BCRYPT);
        return 
$this;
    }

Even empty password supplied, it would not trigger the validation error from model!
What is solution?


RE: If hashed password in entity, it is not get validate length of model validation - iRedds - 04-18-2021

Don't use model validation. =)


RE: If hashed password in entity, it is not get validate length of model validation - ipmeel - 04-18-2021

(04-18-2021, 12:46 PM)iRedds Wrote: Don't use model validation. =)
If the model validations not used, the email validation (is_unique) would not work! Idea
PHP Code:
'email' => 'required|valid_email|is_unique[users.email]'



RE: If hashed password in entity, it is not get validate length of model validation - iRedds - 04-18-2021

Validation is a separate library. You can use it without a model.