What are the potential risks of converting a password hash from MD5 to SHA512 in a PHP system?

Converting a password hash from MD5 to SHA512 in a PHP system can potentially lead to compatibility issues with existing passwords stored in MD5 format. To mitigate this risk, you should update your system to hash passwords using SHA512 for new users while maintaining the ability to verify MD5 hashes for existing users during the transition period.

// Function to hash a password using SHA512
function hashPassword($password) {
    return hash('sha512', $password);
}

// Function to verify a password against an MD5 hash
function verifyPassword($password, $hash) {
    if (strlen($hash) === 32 && md5($password) === $hash) {
        return true;
    } elseif (hash('sha512', $password) === $hash) {
        return true;
    } else {
        return false;
    }
}