Change Password Validation in the previous 3 password

Hello everyone. Any idea on how to validate the user password?
Here is the logic: The password will not be save if the user use the password again from the previous three(3) password he/she used before.

Any idea or method will be appreciated.
Thank you!