Login and Signup using Firebase Realtime Database in Android Studio | Explanation Video

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to my channel in this video we will be creating login and sign up using Firebase realtime database so basically you will store multiple data at the time of sign up and use those data as login credentials for example I'll be storing email name password and username out of which I'll be using username and password as a login credentials simple right but what exactly is Firebase realtime database Firebase realtime database is a nosql database that allows you to store and synchronize data in real time basically it will help you to build real-time applications such as chat applications collaborative to-do list social media and many more without any need of complex server site code great right but instead of Firebase realtime database you want to go for Firebase authentication then I already uploaded a video on it you can click on the I button to watch so yeah with that said let's move to our Android Studio open Android studio and choose empty activity name the project as sign up login real time and language as Java click on finish as we are using Firebase real time we need to enable few Firebase setting to connect it with our project go to realtime database then click on get started with realtime database click on connect to Firebase and then build it will automatically going to open Firebase console in your browser then click on ADD project and keep the name as it is you guys can enable analytics no problem click on connect and continue now click on ADD realtime database SDK so basically it will automatically going to add realtime database dependency in your gradal file once the project is connected go back to our Firebase project click on build and then realtime database now click on create database keep the location setting as it is start in locked mode have few restrictions when it come to accessing the data so as a beginner it is better to go for start in test mode then click enable as of now there is no data present in the realtime database hence it is showing as null finally we are done with all the Firebase settings and now let's move to our prerequisites go to colors. XML press contrl + D to duplicate the line and name the color as lavender then the hex code AS 8692 F7 now go to themes. XML change the theme from dark action bar to no action bar then change the color primary and color primary variant as lender then right click on drawable folder we will create a lavender B which will act as a border around the edit text change the root element as shape and click okay give the shape as rectangle and then create a stroke with two de thickness and coloriz lavender then lastly Corner radius as 30 DP now we will add background image so copy the background image and paste it in the drawable folder now we require four Vector asset beside the edit text so right click on drawable then click on new Vector asset and type name as email let me quickly add all of [Music] them and done now we need to create snup activity so right click on package name name it as signup activity and click launcher activity so when you open the app the signup activity will be the first screen to be shown also we need to create login activity as well so same procedure and name it as login activity then click finish we also require helper class so right click on package name then new then Java class now go to Android manifest by default our launcher screen is main activity but we created signup activity as a launcher screen right so remove the launcher intent filter from Main activity section and Export it will be through only for the launcher screen so make it as false now close all the tabs now go to activity signup we will be using linear layout instead of constraint layout and then keep orientation as vertical gravity as Center and add a background image you can download the background image from the description box now add a card view then give it a radius as 30 DP and elevation as 20 DP then inside the card view add a linear layout then again if the orientation is vertical I added lavender border as a background to linear layout so basically it will create a border around the layout now add a text view that will act as a sign up heing then create an edit text for name and then give it an ID as sign upore name add background as lavender border which will create a border around the edit text then add a designated icon in the drawable folder and give it a decent padding now copy the entire edit text and paste it we will use this edit text for email so for that change the ID hint and then drawable left icon again paste the same code for username edit text similarly change ID hint and drawable left icon then again paste the the same code for password edit text change few attributes and add input type as text password which will turn your password into EST now create a sign up button then IDs sign upore button and Corner radius as 20 DP lastly create a text view that will redirect the user from sign up activity to login activity and we will give it as ID login redirect text and done now copy the entire XML code because we will be using the same code in the activity login with few changes paste the code in activity login firstly change the context to login activity and then change the Hing as login now remove email and name edit text because for login we will be using credentials as username and password only then change the ID as loginor user username and similarly loginor password now change button text from sign up to login and also its ID lastly change the text and ID this text view will redirect the user from login activity to sign up activity using intent then change the margin top of login username from 20 DP to 40 DP now go to activity main this will be our homepage so first add a background then change the text and give the Tex size as 36 SP and color as white and done go to helper class declare all the variables that we will be storing in fireb real time database now right click then select generate and then click on Constructor it will be an empty Constructor and select only the class name and click okay now again we will create a Constructor but with all the variables so click on generate then Constructor then select all the variables and click okay then we will generate getter Setter for that right click then generate and then click on getter setter select all the variables and click okay and we are done now go to signup activity declare all the necessary variables as we are using Firebase real time so we need to declare Firebase database and database reference now initialize all of them then add on click listener on sign up button firstly initialize database and reference users is referred to as a parent name in the Firebase database now with the help of get text to string take the input value from user through edit text then call the helper class and mention all the associated variables as I previously said our parent name is users and our child name is name but in the part two video I have rectified my mistake that reference child will be username instead of name you can refer the PIN command for more detail now add a toast as sign up successful and create intent that will redirect the user to login activity once successfully registered lastly add on click listener on login redirect t view where we will create an intent that will lead user from sign up page to login page and done now let's move to login activity declare all the necessary variables now initialize all of them as I previously said for the credentials part we will be using username and password so for that we need to validate username firstly take the user input value from login edit text and store it in well variable then if well that is username is empty and error will be thrown as username cannot be empty else it won't throw any error which will be null now copy the entire validate username and paste it again because we will be using this one for validating password change the edit text as login password and also the text now create a meod name as check user which will check if the user is present in the database or not so take the input value from edit text with the help of K text to string and store it in user username and user password variable respectively then database reference will refer the exact parent name that we created at the time of sign up which we named as users now with the help of query we will compare the username that is already stored in the database with the username that user provided and the time of login and then the comparison will be stored in check user database variable now add listener for single value event on check user database variable it will automatically going to create two method that is data change and on canell so it says if snapshot exist which means means if user exist then error will be null then user names child value that is password is stored in password from database variable okay now it will compare the password that is present in the database with the user password that will be provided at the time of login also please rectify the code for more details you can check the pin comment so if the password matches then the error will be null then create an intent that will redirect the user from login activity to main activity or else that means if the password does not match then it will throw an error as invalid credentials also request Focus method is used to request that the given edit text view gets the focus which which means it will be ready to receive input from the user then referring to our previous if we will write our else that means the user does not exist hence it will throw an error as user does not exist simple now add on click listener on login button where we will call all the methods so first if validate username and validate password is not true then nothing will work else if validate username and validate password is true then check user method will work lastly add on click listener on sign up redirect text view where we will create an intent that will lead the user from login page to signup page and done now let's run the app enter all the values name email username and password then click on sign up our parent is created as users whose child is username which will store all the values now let's log in with the respective credentials click on login button and then we are successfully logged in into our apps home page so yeah that is it for the video if you're new to this Channel please consider subscribing to my channel and I'll see you in the next [Music] video
Info
Channel: Android Knowledge
Views: 37,603
Rating: undefined out of 5
Keywords: firebase authentication android studio, firebase android studio tutorial, login with firebase android studio, firebase login signup, firebase login, firebase sign up, firebase signup, register with firebase android, firebase authentication, firebase auth, firebase tutorial, firebase new user, firebase auth tutorial, firebase authentication tutorial, email authentication firebase android, firebase create new user, firebase, login page, login design android, signup page, android
Id: M3gYcPF51QY
Channel Id: undefined
Length: 23min 21sec (1401 seconds)
Published: Fri Apr 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.