I use Respect Validation for password matches on a Slim app:
class PasswordController extends Controller
{
;
;
public function postChangePassword($request, $response) {
$validation = $this->validator->validate($request, [
'password_old' => v::noWhitespace()->notEmpty()->matchesPassword($this->auth->user()->password),
'password' => v::noWhitespace()->notEmpty()
]);
if($validation->failed()) {
// stay on the same page
}
die('update password');
}
}
I can authenticate the password:
class MatchesPassword extends AbstractRule
{
protected $password;
public function __construct($password) {
$this->password = $password;
}
public function validate($input) {
// compare the non-hashed input with the already hashed password
}
}
...and I created my own custom string for the 3rd rule ('password_old'):
class MatchesPasswordException extends ValidationException
{
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Password does not match.',
],
];
}
The script works fine, I get the following message when I submit with 'password_old' field empty:
"Password_old must not be empty"
I would like to change the above default message to a custom string, e.g.:
"The value must not be empty"