Authentication firebase

πŸ” Authentication firebase in Android Studio: Full Guide (2025)

 

Authentication firebase
Authentication firebase

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

  1. Go to https://console.firebase.google.com

  2. Click β€œAdd Project”

  3. Follow the setup wizard (no need for Google Analytics)

  4. 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.json and move it to:
    app/ directory of your Android project.


πŸ“Œ Step 3: Add Firebase SDKs to Your App

Open your build.gradle (project-level):

groovy
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}

In build.gradle (app-level):

groovy
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

  1. Go to Firebase Console β†’ Authentication

  2. Click Sign-in method

  3. Enable Email/Password

  4. Save changes βœ…


πŸ“Œ Step 5: Create Login & Signup UI

Example layout for activity_login.xml:

xml
<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:

java
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:

  1. In Firebase Console β†’ Authentication β†’ Sign-in Method β†’ Enable Google

  2. Add to build.gradle (app):

groovy
implementation 'com.google.android.gms:play-services-auth:21.0.0'
  1. Configure Google Sign-In:

java
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);

  1. Handle login in onActivityResult() using:

java
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

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top