Login and Registration REST API using Spring Boot Mysql

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi friends welcome to tutors funny Channel today I am going to make the spring boot application registration form and login so using restful API so how to set the registration form with the ash password how to set the ash password mean how to give the secret right so let's check it first I am going to register a user so this is the API we have set it first we have run the project and reset the API on pause man if you are not install the post Mentor you have to install that right here we are here we have we have set tested the back end so now here first I'm going to save the record click Send here record has been saved okay now if you want to see the records back to your Intel J application here this is the employee table double click on this one now you can see here here and this is the email address I set it the name and this is the hash path okay now the hash password will be set okay this is the ash part now let me test the login so here when you log in we don't need this field only we have tested login say Okay login right we will test it okay so here if I enter that another two let's send it here password not match status false right so now let's let's type the correct password and test that here login success is working now if you are type that email address right if you type any other email if you click any other things here additionally I have entered and set it again here email not text it okay so this kind of validation how to set it okay we'll teach step by step right now let's back to our uh IntelliJ application right now I'm going to create the new spring boot application so go to I'm going to uh I'm going to uh type Spring Book spring initializer you get it this one click on this here this is the here we have considered our project so first we have to click on the maven protect Maven I need maven with Java language Java so here spring boot applications are set it as this one defaulty we select access right so here uh springboard here you have to group have set it here as example okay name only you have given here as uh yeah just give the name here as log registration login register login I give a name right so here this is the package com example register work okay here this one should be it javai I have installed in a machine Java if you are inside I have recommended the Java it is stable version you have download them right and install them after that you have set the dependency click and dependency see your first time going to at the report.c as jpa second one I'm going to add it here as web sorry web p no need done uh jpa second one is the MySQL foreign [Music] generator now we have here the file will be downloaded now we have to configure that right we have to open now open on the uh Intel G idea so here go show I just cut off this one back to my f drive here I'm going to paste it right click extract file click ok right now the application is this one now this one I will open on the integer idea so go to the Intel J you have to open them open where you have put it put it as F Drive which name is registration and login when you open the file be careful how to open ILP teach you okay so here what's the name registration register login key don't open click and open okay don't open this way here inside this photo you are expanding inside the folder where the iso folder which is created by created login register login click on this folder and open it okay I have open right first project I'm going to open up new window go through that uh project guidance so that I open on the review you don't do anything else it will be getting the whatever dependency you have put it here on the poem.xml so all the dependency will be configuring here okay dependency here so don't close it but wait until the dependency get installed after install them you you can have this folder okay here all the papers get told them you will be able to expand this is slow project here go to the form.exm here you are all the dependencies is installed here you can see here whatever difference you are selected here jpa and security and web MySQL connector these are the dependency of we have selected okay the security must be we select as a select a login this one okay we have selectivities needed this dependency also needed right so if you want to add another dependencies if you are forgot to add the dependencies over here how to add the dependencies your type foreign okay okay I I take the example of MySQL if you forget forgotten to uh at the dependency showing how to get them you type MPN MySQL sorry mbn not mvbn it cause the dependency is called so the respective dependency page here you can get the version right so okay you just get don't get the new one latest one you would get at least it's by this one you get it here you have to select the dependencies copy it and paste it on the form.xml file go and have it here you just paste it over here then it will be update right so it it definitely so here just paste it let me check here this kind of uh loading bar will be there here you click on this one it will be update right it's already there that's why it will be taking error okay it's already there right perfect now let's go to the project right first I'm going to go to SRC main Java inside the Java we have our registration login this is our main method of job this is the main method it is reside on the SRC main Java this is a package it will be defaulty it will be installed right now here first I am going to press the new controller so right click new package this one should be the controller so first what is the control amplit employee controller employee controller right don't give their name as your employee control sorry control right the employee controller has been created now we have to add another things dto and entity right repo service right you have to create these following packages second packages video that one say entity entity entity are depend dto employee controller entity another package we need is uh service order repo we have to select your Quarry will be working Ripple reports apart we are coming with the database right so here right so the controller it will be managing the project so another one is we have to forget it just a sex config this one should be the most right perfect okay these are the packages you must create it right now first what I am going to use controller right click here oh your class you're better class here the classic class this class here we have Traders employee controller right say empty controller now we have to add The annotation is following annotation we have to edit we go to the employee controller rest controller cross origin okay it will be this one should be masked when you are connected with the front-end application request mapping this is the API VR settings okay this is a restful API so you have to implement the risk controller so this in since springboard how to manage their the all the project structure they are Implement The annotation so simple if this is a restful APS or you have to write the other restful API so you're at rest controller got implemented here after that this one works for the front-end part if you connect the front end okay this this is a backend it's a crossover in this must second one third one should be the request Mappy why we implement this annotation DC notation we are implemented restful API request okay so we have to set the path uh so here like this you have to this is the correct way you edit you're right like this API which this one you have to write slash version is employee right employment this is how we have write the request okay write that like this okay right this one should be the port what is the port you are setting right so we have uh talk it little bit later on this one we have to understand so far this is enough right after that employee controller what I'm going to do is here first I'm going to create the function so how to get the functions first you have to write this like this Postman this function right so right here uh I just copy and paste it so here because it takes too much time to complete it otherwise right so first you have to write Postman a postman posterior post post sorry post mapping because we are posting the values when you save the record we are posting the values okay so we already post mapping when you get their values from the database and get mapping so the postman path save that when the request is coming like save here if you're right save okay save I already saw this one record will be saved in the database so we have to write a save here so you have to identify the functions public string save employee body requires we have to get the details from the dto we are the employee detail here we haven't created this class so we have to show this trademark right right okay we get the details from via employee region right now first I'm going to create the entities right employee right employers employee name so so address so employee name username password right three Fields enough if you want more field you have done it okay employee name first name last name mobile number age all the whatever you can edit okay this example I added this three okay if you want to write it right so yeah before that your set like this if it is entity you have said this called annotation entity and table right what is the table we have create on the database right so here we have to add that you have to call the entities here this annotation okay right I just copy and paste it you have to write yourself okay so how to write it simply got annotation entity Lord get it then click on here get there right you have to get them here if you import it it is come okay if I if I copy and paste it it asks red mark because we have to implement the package so here how to implement the package art class enter then it asked him for the class this is a class inside of the package it will import right okay that's it okay this is how we have Implement The annotation okay this is the table name employee why this table name the database table is all the records should be saved in the database table so the table name I have here uh here I have implemented here as employee the employee this this employee name in our database tables will be created right now here I'm going to create that this following attributes what are the attributes vectors so here is copied and paste it I'll be explained already first here ID write ID so you have to implement The annotation yeah the right ID right okay ID after the column so we have a lot plus Enter key in only the all things are classes and imported right so this is a column column this is a column where in our database so it will be a auto Implement employee ID length I given as 45 generate value here set as generation type autumni when the record is added the employee ID will be added automatically so we have set like this right length I have set it 45 this is the this this is the ma this is the attribute I have set at employee ID this is the column database column name this is our form our restful API we are sent like this employee right employee name employee name we have to create in our database table employee name look like this okay so here if you want to story so here the example here right here the early example I showed you this one right in our form field this restful API we have to write like this okay your form field closet here you are right okay this is a form field this is the database we have set it okay all right that's how we operate okay right it's a database we have created the employee name here on the length is the length this is the employee name second third one is a email and password these are the attribute layer set right so this ID field so that we have to give The annotation ID this is a column this is the autoinkable these three things we have set it to that rest of the column you have to we have we have only one annotation is there column you have given the column name what's the column in your database This Record should be added you have to given key right now let's at the Constructor and non parameter Constructor and empty Constructor and get and set method and string function these are must okay then this all the values we are getting to the outside we need that function so right click so this one right click we don't try to you don't need to uh type it just generate okay generate Constructor first to all things okay you're getting there all the construct values construct the values are coming via the Constructor a employee name email password like this second one right click generate Constructor this is non-constructor now the empty construct after that you have to implement the get and set method right click right click uh generate get unset method will be selected right what happened here select okay how does we need another one right click generate we need this one string two string method also we need click OK right perfect this is how we have at the end case okay these are the identity will be calling the database right at the data into the data yes so here right now what I'm going to decide I need to detail I'm going to create this this all things we need only the dto class new class is employee dto dto right employee dto here we need only that things we now need to do this this all the things we copy it just copy this on the on the things you want to paste it the video nothing to do it only the values we need at least all things we now needed you have to cut it it's only that this here we are not creating the table and only the passing the values so we have to know the details like this simple okay detail this is how we have created employee right the DTR also we have posted all things but thanks right click generate we need a Constructor call The Constructor select an okay after that we have select the uh get unset method and empty Constructor you have to get the empty sense structure none so right click uh generate get and set method as well select all and get transcript of the texture right however we have need a sync also right click strings function also neat generate string that's it that's thing here correct for fine now what I'm going to do is now we have a detail now here when the customer comes here this employee details there it's a detail okay first what you're going to do is go to import the class so you have to select here but here we have to write you have to call it here so this one what is our executives are coming when the postman it's coming to the control so here when rectus is coming save put it here and pass it to here okay so here it go to that which it's called in the employee service at the employee method so now we didn't write the employee service center so now I'm going to go to created Employee Service here uh you're trying to create a class employee service so yeah versus a class employee subscribe table service but foreign employee services are not a class sorry for that this one service select this one new Java class employee service is not a class which is an interface they are called this interface only we can't do anything only we have to declare the method on this interface right syntax right the interface way up to this one okay Employee Service like Employee Services employee service we have to call that annotation whatever annotation also via record right so how to declare The annotation this one Auto VR sorry not here this inside the class right whatever right so we are Employee Services yeah so it will be here that Employee Service the employee service will write here Employee Service uh this one here simple service class Employee Service the same name you got the employee service right now here we have to create a method you don't need to create click on here create method should be there click on this it will be created here okay it automatically create the method you don't need to create that one okay right perfect it's working perfect right now what I'm going to do is it's working for a fact no problem right now after that what you are going to do is I'm going to to select the service I'm going to create the end of the package which is a impl same limitation by MPL right here where we have to create another class which is a employee MPL right employee select the package new class should create as employee impl IEM likes now this impl class is traded successfully now I have to implement that this interface employer interface right so you have to write the key your type implements Employee Service not get this this class right so this is glass skating now it is not a right task to implement this method we only we have to return the method but we have we just implement the method only we have to work through this method here right so click on here is by python implement this method this method click on right it is implemented successfully right now here what I am going to do is I am going to add the records into the database right so before that now this is the flow we have a contour like this throw in the record to service will be service will be passing the record repo so repo also we have to get the report asset so you're right class employee report this is also the interface what are classes interface your repo interface right now here what I'm gonna do is this interface I'm going to implement these annotations what are the intertations enable jpa repository and preposition you have to implement this two annotation which will be managed the repository part after that we are trying to extend your right like this is interface you have right okay The Exchange keyword extends JP Repository here employee which is entity here this first one should be integer mean this ID what's ID in the entity what is the type say integer type this is integer type you write the integer okay so you have to what's the idea it's the primary key what is the primary also that first integer outside import that entity so select this one or enter PT for the class but that's it if you're writing you just step by step you're trying to extend or JP repository employee integer right okay if I return and explain it they take too much of time to complete this project okay now here what I'm going to say that's it that's the thing helped right okay that's the thing we have to write now let's back to my impl here I have to uh Call the call of a uh repo so your three four we have to Auto react we are right here's report right Auto where Auto where you have tried this repo this class is repo you're right like this so yeah employee repo it just simply the class what perfect and it's perfect now what I'm going to do is here uh employee M here you have to return the so null right here I'll be explained don't worry just copy and paste it and I'll be explained in dot dot it right now here what I did here is right so here this class I have to return the employee employment is entity employee class entity you have create the object employee new employee we have great object employee right the employee class this employee class we have to use that this all the properties okay ID should be automatic treatment we don't need them we need employee name email and password right we have to be out of type like the same to any password so here the same thing it will be coming to the employee service here so if the data is coming from the dto employee dto for this employee detail so employee detail so you have write this employee detail same employee dto object here to employee detail right it's coming here get the data and set into the entity so the so outside the entity employee this entity we have created object employee this GT object dot get to employee get employee ID employee name that we have another field which is a buffer The password should be what is the password this encoder we outside the ash password so we have to write the password encoder so this one this class also you have to add this annotation okay so right private password encoder password so so here this one discussed out right okay then only we have to add the encode parser so when the the where we are not set the password uh buffer encoder password code so you're like this password encoder in code whatever password your type it will be encoded and saved testing you have right after that click save button it will be returned back to the get employee name so okay this is a get employee name so you have to skip the employee employee class there the topic but it's not creating get team flowing it so you're right so get employee what is your name foreign employee get employee name right okay right perfect this one you'll get there right you need to the employee ID employee name this one should be Auto increment this one employee name employee address email address password your settings it's called the repo this report save here call this employee object over here record is saved the record is coming via the video it's set into the entity after that it's all the Blackboard will be saved in the entity object entity object you are calling to the repo repo right it will be saved the repo is a part where communicate the database add the recording to the database after that after that it will be returned back to that a message employee get employee neighbors employee name your written here it will be getting if you have the ID also passed your ID also you can get it okay this is the thing the record is set okay very simple right now let's save our right now let's see go to the resources folder application property here we have to configure our database connection right so do you no need to also subscribe provide you don't worry here the application property here configuration okay so a spring boot application name this is our registration or registration logic I just click that project name right this is a port where we are we are running the server so if you want to change the port I am going to change the port of portf 980 90 this is the port where my project need to run so we have to set the port like this here jpa hibernate selected create so in the first time you upgrade the database you have create this is this one should be our MySQL driver your specify the MySQL driver right after that spring data source here your database connection you are given here this is the port in our laplos this is our database I have created whatever name I'm going to get the name as DB create database if not exit true okay the simple code okay this is the value installing that uh MySQL work patch okay what is the username and password you are given you have to write like this okay then you have to the MySQL workby if you are not installed by my SQL work back you have to install them MySQL work batch foreign right okay after that you have write this simple jpa configuration you have right like this okay this is all the source code I provide you you just copy and paste it you have to understand what is what is here this code only have to work this is a default jpa configuration when you install the MySQL connection these are the this is the database I have created this is username and password right this is a database I haven't created now I am going to create a database okay so this is simple stuff now let's create a database so all things have deleted right here let's run and check whether it's working fine or not uh go to the controller now let's run the project now you can see here the database is created the table has been all things are here created here create the tables you can see here right so you can see check after that what you're going to do is you have to go to the database section your database you cannot do anything else you have to create the database okay so here click on here database data source here what is the name here we have given application property this this DB office so go to the database here you can see the database click on this data source you have to get the database minus MySQL so log loss username is root password is root one two three database DB office you can check the connectivity connection success okay connection success right click apply ok now you can have a you can stick your database this is a database configuration your table here's a table which is an employee these are the following these are all things related right okay right this is how we upgraded everything right now let's do that uh another thing is we don't need have any problem let's test that whether record is added or not right now you can see here the port what is the port you have given here 80 90 support okay so if you are not download the postman you have download The Postman have http you select here as a click yes okay HTTP slash local loss okay you don't specify the port what is the post you are given after that this one should be the API how to get this API you set it here you can see here this is the API okay API version employees via V1 in the version okay this is the efficient way to set the API slash when the request is coming save it goes to the it goes to save method here what that says first get the record from the dto and in passing to the service service will be passing to that uh repo okay that's how the flow is working now let's check okay before that we have a do anything else here the config we have to create this configuration part so the password security here we have a separate configure passage this one uh we go to the impl you can see here we have implement the password encoder so we have to add the the config we have created the package we have to new other class you type config security config you have to create the class so that purpose here we have to give the uh without you to import the class so you have write like this you're talking about being let's say the b in here being power for encoder you have set this password encoder here we have to import the class your type like this okay be in password encode so type password encoder right okay you have to type like this password encoder uh this one okay return this perfect okay so okay then only now you can see and check now here also you can check here the configuration you write a configuration here configuration is an annotation here right configuration is annotation this is the configuration this is a configuration annotation now let's run and check now it's working now it's working you can see this now it's working now let's test it whether it's the coding is working or not right now what I'm going to do is if we have already this is this is our low cost you support where we running our service so which support you can go to the project you can see inside the application property this support we set it okay so localhost that post and employee control this is your API version employee so employee version employee the save method you can see the same right so let's try try on this uh click on this right now let's go and check it the database double click on this here it's okay the password is will be created here like this okay I have four factors working perfectly well now if there are any problem while create this security so okay go to the main method registration login application you have to write like this springboard only this annotation will there this is the main class or main class here you have to write this exclude spring Auto the security Auto configuration class we have to write like this you have to get exclude then it's right is there any problem while you get it right okay you have to implement this that's it that's the thing right now after that we have to start with the login now let's start the login so first login uh The Entity also the same entity so here we have a dto we have in login we have to create the different detail new class this one should be the login detail okay the login detail foreign class okay you have to write you have to implement this following method here only we need only those these two Fields okay this dto go through this Fields okay this video as we have these two Fields have email and password only we have we we are checking so then what you are going to do is you have to write first you have to add the Constructor so generate Constructor Constructor get and set method or that you have sit there string menu right click generate screen two string method that's it that's the thing you have right okay after that we have to go to the controller employee controller you have to write you have to implement this one this method when the request is coming right I just copy and paste it and I'll be explained don't worry this course code I provide you your right post mapping path login if you type like this login is go up to the login function okay but here this one you have tried public response entity order response this is a response but get the response right but the password is succeed or not import the class already have if if any red Sean you are tried click on here press alt and enter it will be gone okay so here uh this login message if you have we haven't created this class okay employee service and check it login employee okay so here we have to create the class again this one we have to create click on this create the log Employee Service at login it will be created now what you are going to do is here go to the impl foreign click on here implement the method click the method will be imported here it will be imported successfully now what I'm going to do is here we have to login message the message will be displayed okay so we have to create simply uh this section response section payout response right so you have to write this one message login message so if you have right you go right here what you're going to do is uh we have to go to here I'm going to create another package select this one and the package here create response response here you have to create the class login response response I get login response for login okay what I'm going to do is here we have to this class we have a two message and Status right okay here also you have to import the garden set method so generate Constructor we have to argument Constructor we have to pass the empty Constructor as well uh generate empty Constructor none after that you have to generate the get and set method after the period set one another one thing is two strings select this one generate two string method also we have to implement this all things solve it right now what I'm going to do is this one login response let's go to controller This One login response at your mark you have to import the class award present okay login response right login response right so okay the same thing name we are given here this should I also login response response plus responses it's the same thing copied this one also pop it and paste it over here login and response this class uses the impl also login response okay login response right login response right login response so login response sorry login response right login transforms uh okay the same service also login response right perfect right now what your time card here is here I'm going to check it right foreign checker just copied and paste I'll be explained don't worry right okay what I'm going to do is this on all the things that routine response okay right here the here what I did here is here when the URL coming to the controller here login it's it's closer you get the details only employee uh dto coming this only email and password passing to this controller get them receive them and pass into the Via Service employee service login method so it goes to the login method over here foreign now here get the data and here check it first you have to create the variable message employee you have right employee one your create employment object here you have to go and check the uh report so repo go to the employee repo here uh we have these two things we have to copy and this one we are PC toolkit created paste inside here right now in repo your right optional employee your find one by in a email and password okay what is the password coming from the dto your pass it here and check it okay this is the simple select store after that we have to separately we have checked the email also whether the email is valid or not find email right so let's back to our but your check uh repo find email here the email is valid it's it the email is valid email it's go and check share this one if it is not null records here our what is the password you are getting password in code password you're right here Boolean password right here write encoder match your start with your match password Encore match your brightness and here we have to check it if the username and password valid or not foreign [Music] success otherwise login failure right login free okay right okay after that if the ID password dot not match it will be passing error password not much if there is any error of the email that this email is not valid here firstly or check the email first the email is not valid it it will be written the messages email is not exists okay we have put the messages right now let's test that now let's test that again we have to run the query and check it right and now I am going to add the new record uh here I'm going to James you applied James Gmail here password is this right now let's send record Adder now I'm going to test that through login here we have quite login right login button here record is Success so here this both record is match it will be written in the message login success if there any problem with the email not text is here you can see here first you have to firstly validate the email then only if the email is exist only it will be go and check the password so it will be written email is not taxes right if they are username and password file it will be working here login free so here if you are writing that here uh sorry but right right now if you write the password wrong you can see here password not match okay password not much right here is working it's a login success it's very simple this area make the simple login and uh we make the login and registration page using the ash password all the source code I provide you thank you for watching
Info
Channel: Tutus Funny
Views: 83,085
Rating: undefined out of 5
Keywords: spring boot security, Login and Registration REST API using Spring Boot Mysql, Login and Registration Spring Boot, Registration Spring Boot, Login Spring Boot, Login hashpassword, Registration Login hashpassword
Id: ug3K7h0LbJ0
Channel Id: undefined
Length: 48min 58sec (2938 seconds)
Published: Thu Feb 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.