r/PHPhelp • u/movieguy95453 • Dec 16 '18
Password security with PHP and MySQL
I have an employee portal for my company's web site. I'm curious if the following is adequate password security considering the site does not contain any confidential information beyond the work schedule. Also, if someone were to gain access to the site they would not have access to any internal business system as the portal resides on a completely different and unrelated server.
When an employee record is completed, or a password updated, I use the crypt function to hash the password. For the 'salt' I generate a random string of 5-10 alpha numeric characters (length is randomly selected) . After hashing the password the salt is stored in the database along with the hashed password.
When the employee logs in the system grabs the salt which matches their username, and uses it to hash the entered password before matching it to the stored password.
17
u/truechange Dec 16 '18
Read on password_hash() and password_verify(), then use those instead.
It will take care of salting for you and automatically upgrade the hash algo in the future.
1
u/Dr_Midnight Dec 16 '18
and automatically upgrade the hash algo in the future.
...only if
password_needs_rehashis used. Just wanted to make sure that tidbit wasn't forgotten.1
u/truechange Dec 16 '18
AFAIK when using password_hash() with PASSWORD_DEFAULT as $algo, this is done automatically.
password_needs_rehash() is used when you're doing things manually.
1
1
0
2
u/[deleted] Dec 16 '18
Use password_hash and password_verify. That's the right way to do this nowadays.
Also, ensure that all database queries are sanitized somehow. And make sure that you're calling an is_user_logged_in() function of some sort before EVERY page.
Do you not have a centralised password system such as LDAP or AD, to save employees from having to create yet another password? (Which, as has been said, will probably end up being their work one again).
Oh, and whose responsibility is patching and maintaining this completely separate server that's outside of your normal business systems? Has it been added to the list?