Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
How to Setup Firebase Email Authentication in Android with Example
Next article icon

How to Setup Firebase Email Authentication in Android with Example

Last Updated : 21 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Service-access permissions are configured using a mechanism called Firebase authentication. This is accomplished by using Google's Firebase APIs and Firebase console to create and manage legitimate user accounts. You'll discover how to integrate Firebase authentication into an Android application in this article.

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.

To do this, launch Android Studio and Create an Empty Activity Project with the following configurations:

  • Name: Geeks for Geeks Auth.
  • Package name: as com.<your_name>.firebaseauth (without spaces).
  • Language: Kotlin.
  • Minimum SDK: API 24: Android 7.0
Firebase Email Authentication in Android
 

Step 2: Signing in to Android Studio

Find the login button in the right corner, and then tap login to log in to your firebase account.

 

Step 3: Creating a Firebase Project

A Firebase project is required, which we will later link to our Android app. We will have access to the majority of Firebase services through this project, including authentication and analytics.

There are various steps in this process:

  1. Launch Firebase, log in using your Google account, and then click the button in the top right corner to get to Firebase Console.
  2. Create a new firebase project, with the name of the project, like the one below:
Image #3: Creating a new project.

        3. Enable the analytics:

Image #4: Enabling the analytics.

Step 4: Connecting Firebase with the Application

A Firebase project can be linked to an Android app in two different methods.

  1. Adding the services configuration file by hand
    You can accomplish this by downloading the google-services.json file, inserting it into the root of the Android project, and manually adding the required dependencies.
  2. You need a running app for this process so that it can communicate with the firebase servers. This shows that the dependencies and project configuration files are functioning as intended. 
  3. Using the Firebase Assistant in Android Studio
    This approach takes care of the majority of the work for you and is simpler and more direct. We'll employ this approach because it is straightforward.
  4. You can then follow this guide to connect firebase to your app.

Step 5: Adding the Firebase Dependencies

Image #5: Adding the Dependencies
classpath 'com.google.gms:google-services:4.3.13'  // Google Services plugin    apply plugin: 'com.google.gms.google-services'  // Google Services plugin    // Import the Firebase BoM  implementation platform('com.google.firebase:firebase-bom:30.3.1')

There is one additional Firebase-related detail. We need to enable email and password authentication in our project's console because we wish to use it. 

Go to Authentication > Sign-in method and activate email and password authentication to accomplish that. This is how it ought to seem.

Image #6: Enabling authentication on the project.

Congratulations!

The configuration of Firebase authentication is complete.

Step 6: Adding the Code Sauce

We will now develop the user interface (UI) and backend for our application. Here's where Kotlin and XML come into play. The firebase APIs will handle the server-side backend for us, so we don't need to code anything. Isn't that fantastic?

We need to keep our app organized first. The term "application architecture" refers to this. The three new packages to be added are extensions, utils, and views. Expand the java directory, right-click on the package name directory, and choose to add.

As we go forward, we'll find out more about them.

Step 7: Working with activity_main.xml

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.

XML
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:chainUseRtl="true"     tools:context=".GfGMainActivity"     tools:ignore="Autofill">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/create_account"         android:textAlignment="center"         android:textColor="@color/black"         android:textSize="20sp"         android:textStyle="bold"         app:layout_constraintBottom_toTopOf="@+id/userMail"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />      <EditText         android:id="@+id/etEmail"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_margin="20dp"         android:hint="@string/email"         android:inputType="textEmailAddress"         android:padding="10dp"         app:layout_constraintBottom_toTopOf="@id/userPassword"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent"         app:layout_constraintVertical_chainStyle="packed" />      <EditText         android:id="@+id/etPassword"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_marginBottom="20dp"         android:hint="@string/password"         android:inputType="textPassword"         android:maxLength="8"         android:padding="10dp"         app:layout_constraintBottom_toTopOf="@id/passwordConfirmation"         app:layout_constraintEnd_toEndOf="@id/etEmail"         app:layout_constraintStart_toStartOf="@id/etEmail"         app:layout_constraintTop_toBottomOf="@id/etEmail" />      <EditText         android:id="@+id/etConfirmPassword"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_marginBottom="20dp"         android:hint="@string/confirm_password"         android:inputType="textPassword"         android:maxLength="8"         android:padding="10dp"         app:layout_constraintBottom_toTopOf="@id/passwordButton"         app:layout_constraintEnd_toEndOf="@id/etPassword"         app:layout_constraintStart_toStartOf="@id/etPassword"         app:layout_constraintTop_toBottomOf="@id/etPassword" /> </androidx.constraintlayout.widget.ConstraintLayout> 

Next Article
How to Setup Firebase Email Authentication in Android with Example

T

therebootedcoder
Improve
Article Tags :
  • Android
  • Firebase

Similar Reads

    Firebase Authentication with Phone Number OTP in Android
    Many apps require their users to be authenticated. So for the purpose of authenticating the apps uses phone number authentication inside their apps. In phone authentication, the user has to verify his identity with his phone number. Inside the app user has to enter his phone number after that he wil
    8 min read
    How to Remove Firebase Authentication in Android Studio?
    Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrains’ IntelliJ IDEA software. Android Studio provides many excellent features that enhance productivity when building Android apps, such as: A blended environment where one can
    2 min read
    How to use Firebase UI Authentication Library in Android?
    Firebase UI is a library provided by Firebase for Android apps which makes or so many tasks easy while integrating Firebase in Android. This library provides so many extra features that we can integrate into our Android very easily. In this article, we will take a look at using this library for addi
    10 min read
    User authentication using Firebase in Android
    Firebase is a platform that helps developers build mobile and web apps. It provides useful tools like databases, cloud storage, and hosting. One of its main features is email and password login, so developers don’t have to create their own system for user authentication. This makes app development e
    7 min read
    Android Jetpack Compose - Phone Authentication using Firebase
    Many apps require their users to be authenticated. So for the purpose of authenticating the apps uses phone number authentication inside their apps. In phone, authentication user has to verify his identity with his phone number. Inside the app user has to enter his phone number after that he will re
    11 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences