Skip to content

This library provides a set of composables for easily integrating One-Time Password (OTP) verification into your Jetpack Compose applications.

Notifications You must be signed in to change notification settings

KishanViramgama/Otp

Repository files navigation

🔐 Jetpack Compose OTP Library

OTP Demo

A lightweight and customizable OTP input solution built with Jetpack Compose ⚡

✨ Features

  • ✅ Simple integration – just drop and use
  • 🔢 Supports any OTP length (4, 6, etc.)
  • 🎨 Fully customizable using Compose Modifier
  • 🔁 Auto focus and intelligent backspace handling
  • 🚀 Callback triggered when OTP entry is completed

📦 Gradle Setup

settings.gradle.kts


dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://jitpack.io") }
    }
}

build.gradle.kts


dependencies {
    implementation("com.github.KishanViramgama:Otp:0.0.2")
}

🚀 Usage


val getOtp = MyOtp(
    otpSize = 4,
    modifier = Modifier.padding(
        start = 10.dp,
        end = 10.dp,
        top = 10.dp
    )
) {
    Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
}

Button(onClick = {
    if (getOtp.isNotEmpty()) {
        Toast.makeText(
            context,
            "OTP Found: $getOtp",
            Toast.LENGTH_SHORT
        ).show()
    } else {
        Toast.makeText(
            context,
            "OTP is empty!",
            Toast.LENGTH_SHORT
        ).show()
    }
}) {
    Text("Get OTP")
}

🔧 Parameters

🧩 Parameter 📖 Description
otpSize: Int Defines how many digits your OTP input will have. Common values: 4 or 6.
modifier: Modifier Customize layout using Jetpack Compose's Modifier (padding, width, alignment).
onOtpComplete: (String) -> Unit Callback triggered when all digits are entered. Returns the full OTP string.

📥 Retrieving OTP Value

The return value from MyOtp(...) is a String that stores the full OTP.

  • 📦 Use it on button click or form submission
  • ⚠️ If OTP is incomplete, it will return an empty string

Tags: Jetpack Compose, OTP, Android, Kotlin, Authentication, UI, Compose UI, Material Design

🤝 Contribution

Want to improve this library? You're welcome! Fork it, raise a PR, or open an issue with your suggestions. Let's build better together 💪

🪪 License

This project is MIT Licensed

Built with ❤️ by Kishan Viramgama

About

This library provides a set of composables for easily integrating One-Time Password (OTP) verification into your Jetpack Compose applications.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages