O'Reilly logo

Web Application Development with Yii 2 and PHP by Jeffrey Winesett, Mark Safronov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hashing a password upon saving a user record

What do we lack in our current scheme? Obviously, before saving a user record in the database, we need to compute the secure hash of the password provided and store the hashed value instead of the plaintext one. More than that, when updating the user record, we don't want to rehash the already hashed value in case we don't change the password at all.

Yii 2 (as well its predecessor, Yii 1.1.x) defines several methods for the instances of the ActiveRecord class, which we can override to do stuff at several predefined stages of the active record life. While you can read about them all in more detail in the Events of \yii\db\BaseActiveRecord section of Chapter 10, Events and Behaviors, we will be using one ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required