🔐 Authentication firebase in Android Studio: Full Guide (2025)

Authentication firebase:In today’s digital world, user authentication is a key part of any mobile application. Whether you’re building a messaging app, an e-commerce platform, or a personal blog app, Firebase Authentication makes it easy to implement secure login and signup systems in your Android app.
In this article, we’ll walk you through Firebase Authentication in Android Studio using Email & Password, Google Sign-In, and more — with source code examples and step-by-step integration.
📦 What is Firebase Authentication?
Firebase Authentication is a free backend service provided by Google Firebase that supports various methods of user authentication:
🔑 Supported Methods:
- 📧 Email & Password
- 🔗 Google, Facebook, Twitter (OAuth Providers)
- 📱 Phone Number
- 🔑 Anonymous Login
- 🧩 Custom Authentication System
Firebase Authentication helps manage users, sessions, and security — without writing your own backend code.
🛠️ Prerequisites
Before integrating Firebase Authentication in your Android app, ensure you have:
✅ Android Studio installed
✅ A Firebase account
✅ A basic Android app project created
🚀 Step-by-Step: Firebase Email/Password Authentication
📌 Step 1: Create a Firebase Project
- Go to https://console.firebase.google.com
- Click “Add Project”
- Follow the setup wizard (no need for Google Analytics)
- Once done, go to Project Overview → click Android icon
📌 Step 2: Register Your Android App
- Package Name: (e.g.,
com.example.myapp) - Download
google-services.jsonand move it to:app/directory of your Android project.
📌 Step 3: Add Firebase SDKs to Your App
Open your build.gradle (project-level):
groovyCopy
Edit
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}
In build.gradle (app-level):
groovyCopy
Edit
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
dependencies {
implementation 'com.google.firebase:firebase-auth:22.3.1'
}
Sync the project to download dependencies.
📌 Step 4: Enable Email/Password Sign-In
- Go to Firebase Console → Authentication
- Click Sign-in method
- Enable Email/Password
- Save changes ✅
📌 Step 5: Create Login & Signup UI
Example layout for activity_login.xml:
xmlCopy
Edit
<EditText
android:id="@+id/emailInput"
android:hint="Email" />
<EditText
android:id="@+id/passwordInput"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:text="Login" />
📌 Step 6: Write Authentication Code
In LoginActivity.java or MainActivity.java:
javaCopy
Edit
FirebaseAuth mAuth = FirebaseAuth.getInstance();
Button loginBtn = findViewById(R.id.loginButton);
loginBtn.setOnClickListener(v -> {
String email = emailInput.getText().toString();
String password = passwordInput.getText().toString();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Toast.makeText(this, "Login Successful!", Toast.LENGTH_SHORT).show();
// Proceed to next activity
} else {
Toast.makeText(this, "Login Failed: " + task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
});
});
🌟 Bonus: Google Sign-In Integration
To allow Google login:
- In Firebase Console → Authentication → Sign-in Method → Enable Google
- Add to
build.gradle (app):
groovyCopy
Edit
implementation 'com.google.android.gms:play-services-auth:21.0.0'
- Configure Google Sign-In:
javaCopy
Edit
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
- Handle login in
onActivityResult()using:
javaCopy
Edit
FirebaseAuth.getInstance().signInWithCredential(credential);
🔐 Firebase Auth Features You’ll Love
💡 Secure User Sessions
💡 Email Verification
💡 Password Reset
💡 Realtime User Management
💡 Built-in Analytics Integration
📋 Best Practices for Firebase Auth
✅ Always validate email format and password length
✅ Use HTTPS for all network calls
✅ Never store passwords locally
✅ Enable reCAPTCHA for phone number login
✅ Use Firebase Rules for database security
💼 Real-World App Ideas Using Firebase Auth
- 👨💼 Job Finder App – Secure user login with resume uploads
- 🛒 Shopping App – User login before order placement
- 🗣️ Chat App – Anonymous login with real-time messaging