Skip to content

Instantly share code, notes, and snippets.

@shahsurajk
Last active June 7, 2022 12:19
Show Gist options
  • Save shahsurajk/8a6e4b050d792d38c4056b808b3cb3df to your computer and use it in GitHub Desktop.
Save shahsurajk/8a6e4b050d792d38c4056b808b3cb3df to your computer and use it in GitHub Desktop.
OTP Service
class OtpService {
// .. other methods for cache store etc.
fun generateAndSendOtp(number: String) {
val otp = generateOtp(number)
// save OTP to cache
// send the OTP to number
sendOtp(number, otp)
}
private fun generateOtp(number: String): String {
// ..
}
private fun sendOtp(number: String, otp: String) {
// .. sending the SMS/EMail
}
fun verifyOtp(number: String, otp: String): Boolean {
// verification with the cache
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment