r/PHPhelp • • 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.

8 Upvotes

12 comments sorted by

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?

1

u/movieguy95453 Dec 16 '18

Yes, each page of the portal checks to see if the user is logged in.

The nature of the business does not have the issue with passwords. Employees use a PIN for the time clock, but otherwise they are not using computers in a way where passwords are an issue. It is a retail/restaurant environment. There is no issue with employees working a terminals where they need to secure data. The sales is handled by an outside vendor.

The portal is hosted on a web server by a third party, so there is no connection to our sales system. The portal does not include any sensitive information which could potentially compromise the business systems. Other than the employee's name and phone number there is no similar data between the portal and the business system.

2

u/cyrusol Dec 17 '18 edited Dec 17 '18

You are just making up excuses for yourself so that we finally tell you "it's okay to build an insecure system in that case, don't bother". It's not - especially since building a secure system is so incredibly trivial/cheap/simple because password_hash() and password_verify() exist. Be thankful they do, use them and then don't bother with it anymore. Using them should take less time for you than replying to me with a "but ...".

https://phptherightway.com/#password_hashing

1

u/movieguy95453 Dec 17 '18

I'm not making excuses, I'm just trying to determine if the security I have now is adequate for the application. I am a business manager, not a developer, so taking it further means learning more than what I currently know. I'm also not suggesting that I won't eventually improve on what I'm doing now. Furthermore, it sounds like password_hash() and password_verify() are primarily just built in functions to do what I am currently doing manually.

1

u/cyrusol Dec 17 '18

Isn't it simpler to use existing built-ins that do the job rather than doing it manually?

1

u/movieguy95453 Dec 17 '18

I don't disagree, but those functions were outside of my knowledge at the time I last updated the portal.

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_rehash is 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

u/[deleted] Dec 16 '18

I’ve been doing uni work all weekend. This really helps. Thank you.

0

u/[deleted] Dec 16 '18

[deleted]

4

u/movieguy95453 Dec 16 '18

That last part makes sense.