Alexander Matrosov Sun Mar 22 18:37:21 -0400 2015

Subject: how to check the length of the password

<?php
static $validates_size_of = [
    ['password', 'minimum' => 6, 'too_short' => 'short password'],
];

public function set_password($password) {
    $this->assign_attribute('password', password_hash($password, PASSWORD_BCRYPT));
}
?>

in this case the length of the password is not checked because after hashing length of 64 characters
You can enter a blank password, and the condition is satisfied

how to check so as not hashed password is longer than 6 characters


Alexander Matrosov Sun Mar 22 19:34:20 -0400 2015

yet solved the problem in this way, but I think it is not very good

function before_save()
{
    if ($this->is_new_record() || $this->attribute_was('password')) {
        $this->password = password_hash($this->password, PASSWORD_BCRYPT);
    }
}

(1-1/1)