package com.drinkool.services; import io.quarkus.redis.datasource.RedisDataSource; import io.quarkus.redis.datasource.value.ValueCommands; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.Random; @ApplicationScoped public class OtpService { private final ValueCommands countCommands; @Inject public OtpService(RedisDataSource ds) { this.countCommands = ds.value(String.class); } public String generateAndSaveOtp(String phone) { String otp = String.format("%06d", new Random().nextInt(1000000)); String key = "otp:" + phone; countCommands.setex(key, 300, otp); return otp; } public boolean verifyOtp(String phone, String inputOtp) { String key = "otp:" + phone; String savedOtp = countCommands.get(key); if (savedOtp != null && savedOtp.equals(inputOtp)) { countCommands.getdel(key); return true; } return false; } }