Go with the PHP route.
Whether you create the logins through PHP or directly through MySQL, they'll still end up in your MySQL database. There are a few differences between the two approaches though. The main point being that if you go the PHP route, your users will be able to create their logins themselves (which means picking out their passwords themselves). If you go the database route, your users will have to have passwords allocated to them.
In MySQL, it's possible to use something like SHA()
to securely hash a password (with a salt), though as far as I'm aware you're unable to pick a more secure encryption algorithm in MySQL. SHA-256 / SHA-512 will almost certainly suffice for your needs, though you may want something a bit more secure.
With PHP, you have access to methods like password_hash()
and password_verify()
, which can be used alongside alongside an algorithm like PASSWORD_BCRYPT
or PASSWORD_ARGON2I
(which is much more secure than the standard SHA-256 or SHA-512).
Finally, you have to consider what should happen in the event of a database breach (which there are roughly 30,000 of every day). As previously stated, the encrypted password is stored in the database in either case. If you create logins through MySQL, you'll likely also be exposing the method of encryption (possibly along with any salts used). If you build the logins through PHP, an attacker would need full shell access to your website in order to be able to work out how you encrypted your passwords.
Most importantly, never give users access to your database. In fact, I would recommend ensuring that your main database user role only has the required privileges to interact with the data (likely SELECT
, INSERT
, UPDATE
) and using a separate user with CREATE
privileges for creation of the users.