I’m working on creating basic password security on a medium size PHP CodeIgniter website. I need to start encrypting password that are being saved into a database. User passwords can be inserted using different methods including CSV import or an individual sign up approach.
Therefore I just want to know at what is the correct level in a MVC system where a password should be encrypted?
The only time you need to perform this function is when adding a new user or updating the password for an existing user. Both of these functions should be performed by the User model. For example, something like:
or:
In this example, the setPassword() method would do the actual encryption.
Also, think of it this way — it shouldn’t be possible to get an unencrypted password into the system. So, you make the User model the only way to interact with users, and have it transparently encrypt all passwords given to it.