A robust Android application that integrates Firebase for OTP (One-Time Password) verification. This project provides a seamless experience for phone number authentication with auto-retrieval of OTP, resend functionality, and a user-friendly interface.
- Phone Number Authentication: Secure user authentication via OTP sent to their phone number.
- Auto OTP Retrieval: Automatically retrieves the OTP from SMS for a smoother user experience.
- Resend OTP: Option to resend OTP in case the original message is missed.
- Firebase Integration: Utilizes Firebase Authentication for managing phone number verification.
- Kotlin Implementation: Entire app built using Kotlin, following best practices and clean code architecture.
- Android Studio: Latest version recommended.
- Firebase Project: You need to have a Firebase project set up.
- Google Play Services: Ensure that Google Play Services is updated on the device.
Follow these steps to set up the project locally:
https://github.com/samyak2403/Firebase-OTP-Verifaction.git
cd Firebase-OTP-Verifaction-repository
This project demonstrates how to implement OTP (One-Time Password) verification in an Android application using Firebase Authentication.
- Prerequisites
- Setup Firebase in Your Project
- Add Required Dependencies
- Implement OTP Verification
- Project Structure
- License
- Android Studio (latest version)
- A Firebase account
- Basic knowledge of Kotlin and Android development
-
Create a Firebase Project:
- Go to the Firebase Console.
- Click on Add Project and follow the instructions to create a new project.
-
Add Your Android App to Firebase:
- In the Firebase Console, select your project and click on Add App.
- Choose Android and enter your app's package name.
- Download the
google-services.json
file and place it in theapp/
directory of your Android project.
-
Generate SHA-256 Key:
- Open a terminal and run the following command:
keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
- If prompted for a password, use
android
(default password). - Copy the SHA-256 key from the output.
- In the Firebase Console, navigate to
Project Settings > General
. Under the Your apps section, click on Add Fingerprint and paste the SHA-256 key.
- Open a terminal and run the following command:
-
Enable Phone Authentication:
- In the Firebase Console, go to
Authentication > Sign-in method
. - Enable the Phone sign-in provider.
- In the Firebase Console, go to
-
Add Google services classpath:
-
In your project-level
build.gradle
file, add the following:buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.google.gms:google-services:4.3.15' // Check for the latest version } }
-
-
Add Firebase dependencies:
-
In your app-level
build.gradle
file, add the Firebase dependencies:plugins { id 'com.android.application' id 'kotlin-android' id 'com.google.gms.google-services' } dependencies { implementation platform('com.google.firebase:firebase-bom:32.0.0') // Check for the latest version implementation 'com.google.firebase:firebase-auth-ktx' }
Add the following permissions and receivers:
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
-
- Sync your project: After adding the dependencies, sync your project in Android Studio.
Follow the steps below to implement OTP verification in your Android app:
-
Request OTP:
- Use Firebase Authentication to send an OTP to the user's phone number.
-
Verify OTP:
- Allow the user to input the OTP and verify it using Firebase Authentication.
For detailed code examples, refer to the official Firebase documentation or the project’s source code.
app/
├── src/main/java/app/my/otpverification/
│ ├── OtpSendActivity.kt # Handles sending OTP
│ ├── OtpVerifyActivity.kt # Handles OTP verification
│ ├── OTP_Receiver.kt # BroadcastReceiver for SMS retrieval
│ └── MainActivity.kt # Post-authentication main screen
└── src/main/res/layout/ # XML layouts for activities
This project is licensed under the MIT License - see the LICENSE file for details.