I’m a bit of a beginner with OOP PHP, but have a fair amount of experience with procedural PHP.
I can’t seem to get my simple OOP login system to work. I’ve tested everything and it seems the login method of my User class isn’t returning any values (I think), but I can’t figure out what is the problem with my code.
Login.zip (6.4 KB)
Could someone please take a look and see where I went wrong?
Also, I would appreciate any suggestions as to how I can improve it (without overcomplicating it).
The most immediate problem with your login system is that the password in the DB is hashed, but the login method is searching for a match to the plain-text password - you need to hash it first and then compare it to what’s in the DB. I’d advise against using MD5 for hashing passwords, as it’s not that secure. It’s better to use PHP built-in (as of v5.5) functions password_hash and password_verify. For older versions, there’s a library available.
Thanks, @fretburner. I can’t believe I left that out. You have no idea how much time I have spent trying to figure out why the login method wasn’t working.
This is for a registration system for small events. The registration process will not be collecting any sensitive information, so I figured that I wouldn’t need anything more secure than MD5. But I will try those PHP built-in functions. I wasn’t aware of their existence.
The registrants will not need to login to anything, this is just for admin area access.
The admin username and password will be entered into the database by hand, because only one administrator needs to be able to access the backend of the registration system. How would that work with password_hash?
Probably the easiest thing to do would be to create a simple PHP script you can run on your local machine to hash and output the password so you can manually add it to the DB.
Thanks, I’ll try that. I’m always open to learning new things like those two functions.
BTW, I fixed my problem with the password, and now everything works fine.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.