Firebase Authentication using Email and Password on Kotlin for android

Ashwin
3 min readNov 29, 2017

--

This article is about creating an authentication for your android applications based on email and password using Firebase. The entire application is built using Kotlin

Adding Firebase Module to the project.

Select Tools — > Firebase to get access to the firebase assistant panel in your Android Studio.

Make sure to sign in to your gmail account from Android Studio to get access to the Google’s Firebase and Cloud functions from your android studio IDE.

Selecting Email and Authentication option.

Make sure to select the email and authentication option from your firebase assistant panel.

Now you can add the following authentication dependencies to the project module by selecting accept changes.

implementation 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-auth:11.0.4'

These lines will be added to the app.gradle file and the gradle files will be synced.

Login Logic.

signInWithEmailAndPassword (email, password)

This method enables user to login into their firebase accounts using email and password.

Realtime Database

Now go to the Firebase assistant panel and select Realtime database option.

Adding dependencies for realtime database to the project.
implementation 'com.google.firebase:firebase-database:11.0.4

Now your realtime database dependencies are added to your project module and are locally available for use.

Register logic.

createUserWithEmailAndPassword (email, password)

This method enables user to register into their firebase accounts using email and password.

DatabaseReference (mDatabase) is created. Now the mDatabase instance and reference from the firebase console has been initialized. Now add the name value to the database by pointing the mDatabase to the “Name” child. Now use the setValue () function to set the value of the name to that database child [setValue(name)].

Fetching Values from database and account signing out logic.

Now set the database reference (mDatabase) for this activity pointing to the name child and attach an addValueEventListener() to listen to the datasnapshot from the firebase database console to fetch the name value from the database.

Now, to log out of the account use signOut () from Firebase Authentication to log out of your firebase account.

Enabling email/password feature in Firebase Console.

Before deploying your application make sure to enable the Email/Password feature under Sign in providers tab from Authentication tab on firebase console.

Registering in your application.
Displaying welcome message by fetching values from the database.

Thanks for reading this article. Hope this helps you. Make sure to share this article. With love Ashwin :)

--

--

Ashwin

I'm Ashzzz, I'm a coder, I love hanging out with crazy people ...I love to share my story