How to verify the generated OTP using TOTP algorithm

We have generated the OTP using Totp algorithm and it would be live for short time. Can you please tell me how to verify generated OTP with user entered otp. Is there any method for compare those or need to store the password somewhere and validate with the entered otp.

Please suggest me which way is best for verifying the OTP that generated using Totp algorithm.