Firebase Authentication with Email and Password in Android Studio | Login & Register Android Studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video i will show you how to authenticate user with firebase using email and password so this is the official documentation of firebase and uh as you can see here the first step is to add firebase in android project so open your android studio and i have already created a new project get a new project and then go to tools click on firebase and from here click on authentication click on the authenticate using a custom authentication system and click on connect to firebase so it will open up your browser and as you can see here i have already two projects in my firebase if you don't have any project in your firebase console so you can add a new project from here and i will choose the demo project click on connect and our firebase project is connected to our android studio now go back to your android studio and click on add the firebase authentication sdk it will add the required dependencies click on accept changes okay as you can see here we are all set and now go back to your browser and go to your firebase console and go to your project go to authentication and go to sign in method and from here enable this email password and click on save okay so it is enabled now just close it and as you can see here the first step is we have to check the user if we if the user is already logged in or sign in so we will show the user the home page our main activity so in my android project as you can see i have already created the login and registrations activities here this is a simple design and as you can see here we have two edit text one button and a text view and in the login screen we have the same things okay so two edit text one for email and other one for password and the one login button and our text register here okay so when the user click on this register here text text view so we will navigate the user to registration activity okay so this is a very simple design and now we will start our recording so first of all we have to check uh if the user is already signed in so uh in your main activity or your home activity override the onstart method and we will use the firebase authentication class here okay so just type firebase auth and i will name it m auth and initialized firebase authentication in your oncreate method okay so now we have to check here we will create a firebase user name it user mouth dot get current user okay so we will check if user is equal to null then we will get the user to login okay so the first step is done and now if we go to the documentation here the third one is create a new account by passing the new user email and add email address and password so for this we will use the create user with email and password method of firebase so i will open my registration activity and same we are using the firebase authentication class i will name it in auth and i will initialize it here we will set a click listener on our registration button we will need to click listener here one for registration button and one for login here text okay so i mean the user click on register button so we will call this method okay and text view login here sit on click list now and the user click on this so i will copy this entry from here we will navigate user to the login activity of the user here is already registered okay so i will create the method here private create user and the first step is to get our text form our edit text and we will store it in a string so i will create a string email and email.gettext to string okay and we will get the password as well password ut registration password it is station password means that edittext so we are getting our text from edit fields okay and next step is to we will check f textures dot is empty email if the user leave the email uh edit text blank so we will show an error to the user okay and we will set the error to 80 registration email save error and we will just simply pass the string email cannot be empty okay and the same thing request focus nsf [Music] textures dot is empty password when the user leave the password field empty so we will show here to the user also so changes to 80 password everything else if user put the email and password then we can uh create the user so we will use the m auth firebase authentication class here and dot create user with email and password so we will pass our email and password here and we will add even here or add on complete listener okay so here we have to check if the task is successful task is successful mean that if the user is created so we will show a toast here to the user and we will user register successfully [Music] and then when the user is created we will navigate the user to the login activity so to do it here and this is true if we have any air so we will show our error post here and i will registration and we will get error as task dot get exception dot get message here okay our registration screen is completed and now we have to add our login so we will do the same firebase authentication in auth and we will initialize it here firebase all don't get instance and in the login we set a click listener on login button and we will pass a method here login user and also we will need a other click listener for our text view so i will copy this entry form here and i will change this to login because this is our login activity login activity and from here we will get the user to registration if the user don't have any account so create this method and start blocking user then we will use the same so i will copy it from here okay press it here and i will use the a key login email edit text for login email and analytics for your password password and complete listener call back here and here we will check if task dot is successful then we will open the home page our main activity and i will show a toast here just copy paste okay so changes to login activity and user logged in successfully and we will get the user to main activity and copy this form here to save some time login [Music] and error and this okay now we are all set and we will go to main activity and as you can see here in the main activity we have a button for log out so if the user click on this logout button we will log out the user tool so and we will navigate the user to the login screen again when the user is signed out so and the most important thing is don't forget to add the intro information here in your manifest file is we are communicating with the firebase server so we need the internet so now i will run the app so as you can see we are not logged in so this is the login page and we don't have any account here so i will click on register here so it will open the registration activity here so i will enter my email and i will set a password and i will click on register so user register successfully and we are navigate back to login so i will enter the email and password to login in my app okay so click on login and user login successfully and as you can see here this is our main activity welcome you are logged in and if i close the application and i open it again so it will open the main activity because we are logged in previously so in the onslaught we are checking so this user is not known so we are not we have we are not going back to login activity so if we click on logout so it will navigate back to the login and if i close this and open the app again so we have to log in again because we are signed out from our account and in the firebase i can show you go to authentication user and this is our user okay so if you want to delete this user you can delete it from here so that's it guys if you like this video share it with your friends and do subscribe to my channel
Info
Channel: CodingZest
Views: 18,230
Rating: undefined out of 5
Keywords: SoftCoding, Android Tutorials, firebase authentication android studio, firebase authentication, authentication with firebase, firebase android studio tutorial, firebase authentication with email and password, login with email and password firebase android, email and password authentication firebase adnroid, email authentication firebase android, register and login with firebase, login with firebase android studio, register with firebase android, register with firebase
Id: iSsa9OlQJms
Channel Id: undefined
Length: 15min 12sec (912 seconds)
Published: Thu Apr 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.