I am building a website and I have just implemented a feature to allow a logged in user to change their password. My current way of validating the password change is very flawed though, for example, it will allow a user to change to a blank password, providing that their old password matches with what they have provided in the form.
I am looking for a way of validating the form using IF statements, that will output an error message into a variable if they make a mistake, so that I can display the error to the user so they know what they are doing wrong.
The code I have at the moment is this:
Code: Select all
$oldpassword = $context->postpar('oldpassword', '');
$newpassword = $context->postpar('newpassword', '');
$repeatpassword = $context->postpar('repeatpassword', '');
$error = array();
//Load user bean using email address and current password (don’t forget to hash)
$user = $context->user();
if ($newpassword == $repeatpassword)
if ($user->pwd == $oldpassword)
$success = 'Your details have been saved';
$error = 'Your Old Password Does Not Match, Please Try Again.';
$error = 'Your New Passwords Do Not Match, Please Try Again.';
I am using RedBeanPHP ORM, however as the problem is with simple IF statements, I was hoping I could get some help on this issue?
The problem is that obviously, this is only outputting a singular error message... So if the users new passwords didnt match, and the old password didnt match the database, it would only display 1 of these errors.
Thank you guys.