You can check/compare customer's old password and updated password value by below code.
<?php
namespace Vendor\Magento\Observer;
use Magento\Framework\Event\ObserverInterface;
class CustomerLogin implements ObserverInterface
{
protected $encryptor;
protected $_messageManager;
protected $objectManager;
public function __construct(
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Framework\ObjectManagerInterface $objectManager
)
{
$this->encryptor = $encryptor;
$this->_messageManager = $messageManager;
$this->objectManager = $objectManager;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$currentPasswordHash = $this->getCurrentPasswordHash($customer->getEntityId());
try{
$newPasswordHash = $this->encryptor->encrypt("new password value");
if($currentPasswordHash == $newPasswordHash){
// password is same
$this->_messageManager->addWarning(__("New Password is same as current password. Please choose another one"));
}
}catch(\Exception $e){
echo 'Error::'.$e->getMessage();
}
}
private function getCurrentPasswordHash($customerId){
$resource = $this->objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql = "Select password_hash from customer_entity WHERE entity_id = ".$customerId;
$hash = $connection->fetchOne($sql);
return $hash;
}
}
Also, if you want to use decrypt password values to compare and check, you can use below line of code in your observer.
$decrypt = $this->encryptor->decrypt("password hash");
Hope it helps!!!