Golang HTTP User Authentication Yabi Series 5 | Golang Web Development | WebAssembly Auth System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello guys welcome back to the channel this is tutorial series number 25 here in maharlikan's code okay we will continue our web development series here guys here in maharaki's code and then particularly in this subtopic which is the golang http users authentication which is the yabby series number five okay so uh we will continue our usage registration guys and uh to all of you happy new year guys and uh [Music] this coming 2021 probably more challenging years for us okay so that's humanity okay so um we will just prepare ourselves for the new pandemic that is uh that is coming in this year 2021 hopefully no no much lockdown again guys okay so just a sideways guys about topic here uh probably um yeah uh we will continue with our golang http uh users authentication uh using this web assembly or wasan pingoling okay so we will continue our usage registration and then we will block um we will block certain users like an any duplicate uh what they call this duplicate username duplicate the email address uh using this our mysql database that we are using in our yabi series here in martin's code so um let's dive into this tutorial guys okay welcome back to the channel guys okay uh we will continue on okay so we will uh this is our last uh part here guys uh in our last state uh using uh still in this uh usage registration here so we will uh having this uh create an account or this one will change this instead of we need to put a registration there in the button okay so and then we will uh in our last discussion we would like to prevent this duplicate username here and then of course the email address we wanted to collect a unique email address per user and this is our propose for this yabi series guys okay so we will continue on we will probably try to empty this one first okay so so that we have a clean uh data here for our harlequins code okay so we will continue with our thing so we would like to create a new function here guys for our thing so last thing is we would like to um i added this one guys for our uh itr log now we need to specify or if you have a config there so we would like to have uh what we call these logs underscore go web app or you underscore your name uh your log name there if you are using the this um itr log guys but i highly recommend you can use this guys this one is a very useful kind of a logging and a robust type of logging uh in golang so this one we will like this one i added in our main route itself so this one is uh added here okay under the our main go main.go uh located in our main and now located in our root directory guys of our project so you can specify here there is a what they call this maximum size and mb you can just specify like a 50 mb for each log size and then there is a max age in day so maximum days probably the one is that we can set to 90 days or it's up to you guys so how many days it can retain there the log size the the log file and then it will be probably removed here let's see what will happen so these are all the things guys uh they initialized for our itr log so probably we don't much deal with this at the moment okay so we will continue on with our thing so what we are going to do now is we what we would like to prevent uh the duplicate username and then we will strengthen our uh users registration guys because this one is the the entry of each user this is a very important one and critical users registration here so we would like to enhance our users registration okay so we will continue on we would like to prevent i think we need to stop this one first okay so i would like to create for this new function guys we would like to create two functions for this uh email and then uh the thing uh for the users uh registration for the duplicate user and then for the duplicate email address so what we can do is uh we need to query our mysql there so okay so we would like to find create a new function called is user uh is username exists okay so let's see if we can okay we'll just uh follow along with this sql here because since we are using the sql or mysql db okay so and then we need the username oh i think we need username only is enough and then we will return this as a boolean kind of thing so of course we need to again guys we need to put some useful information here is to check the vertical check check from the user's table um collection it's okay uh if if what i call if it exists if existed or not then we don't allow okay we don't don't allow to have a duplicate user username uh it must be a unique uh what is all unique value okay enough guys okay and then we will check uh we will query our database here guys so we would like to [Music] uh create some local variable here guys to to get the what they call this id okay so error same thing with our thing but uh we need to use uh same thing guys we need to use the query row okay and then we would like to do some select statement here because our mysql table there there is uh what they call the structure there is a unique id which is this uh the field name is id itself so we can try this okay then uh from then we would like to concatenate guys okay and uh be user dcab user is from our model guys field name there is a constant value so we'd like to concatenate on me so that we will reuse the variable there question mark as our parameter and then the user name we need the username here as a string value and then we would like to do the scanning here scan and then we will store the value guys okay okay so you again as usual we need to check always check this uh error article to nil if any errors there then we would like to you know in this case guessing there is a specific error return from the mysql there no no not this the specific error is a sql dot error no rows you need to specify this error guys otherwise you cannot return then you return with the true this means i will put the note guys return uh return or return arrows okay return no rows this is the exact error guys so uh if this one is no rows then we would like to because in this error guys this one is not totally the error or like a like a debugging debug error or something like that this one is returned from the query row from the mysql official driver there for golang this one will return if if we execute this select statement here this is the the fixed uh error uh error drawn by this library guys so we will specify the sql dot uh error no rows so if no row then we will return it with true that means uh this one is um because we are stating here if it's username exist so probably no rows then we can through this error okay is uh this one is correct then we would like to return as false uh if the standard error there it will be drawn so okay so and then return false so overall it will return false it only will return true if we cannot find if it returns 0 guys or no rows that means this one is this select statement here from the mysql there if we cannot find this username if no existing username there then we will catch this this sql that error no rows that means we will return true the username is not found okay so you just specify more information there so the username is not found actually from the table from the yabi table okay this will be enough so if it returns um no rows guys because this one is it will throw under this error here but actually this error is is a good error because we need to get this one is the sql return rows yeah this one is something like uh this library if we want to visit this um this is so deep this one guys so again it will return rows here so maybe it will take time to dig in this error here okay so [Music] this is the standard error guys okay so it should be enough if this sql statement this query row will return this kind of error i mean this error no rows then we will throw we will return with true because and that means we cannot find uh this user name so what we can do is we need to use this uh username uh let's see if we can find this uh i will try to implement this as well copy this one first okay so we will like we would like to implement this below the email guys maybe here oh here is probably the best place so okay so we would like to create this or probably here guys are all related to the user name uh email is empty email address is valid password username so probably we can check here okay if uh okay if false it will return false then username is not valid so it will return um okay so it will if if it returns returns with false then we can okay so we would like to throw the error there so return zero and then errors dot new you will throw this error kind of thing username is not available something like this please try again and again okay so we will throw this error okay check if the username is available or not okay should be enough so we will have this kind of error message here guys so we will see we will try to run now i think go run may not go okay we will we will try to execute this let's see if we can now we don't have rows yet so okay so we will just uh ctrl f5 we will inspect the element here okay so no errors we'll try to refresh one more time okay we will try the this admin guy so uh and then i would like to use this idea republic email guys okay we will try to use this and then the password let's see some basic uh thing guys password is required okay so we will just uh later we will just enhance this and the maximum number of password guys so uh if the user key and so there's some like a minimum eight characters all these things so uh we will definitely enhance these guys okay so this is our first registration let's see okay okay new user uh successfully created so let's see the table here click the browse okay there is a username admin there and then all the things there okay uh we will try to we would like to change this it's not long it should be registered okay let nevermind will change later okay i will try okay username is not available okay because i never clear all the entries but by default we should clear and then leave with this page but as of the moment we will enhance more our usage registration everything the logix there and then everything the uh the validations will be we should be perfect perfected all this validation because this one is a very important one new users creation failed so username is not available this is the good thing guys we have just created this let's see if it's there okay so it prevents uh that the username is exist so our new function is totally create uh okay guys so if i create like uh like pollets for example we'll try okay then it's totally accepted guys but again we need to prevent this uh email address here um to as a duplicate same case with the the username guys so let's see if it's added okay so the police username there is exist but the email address is uh duplicate guys so we don't want this email address also to be duplicate there as well so we will uh implement this same thing with the username here we will follow with the email address as well okay so we will continue on guys so we will continue so we will continue guys we will just uh probably we will just copy this one guys to capture our time anyway they are actually the same so we can just copy this one okay so is um email it's users user email exists okay so just change with the distinct uh probably you can just uh we can enhance this enhance this more further guys but um like if you want like one function only then we can just change over the the field name here or um then change the field name as well here but in this case um there are some reasons that we would like to prevent in the future like we would like to add further checking here like if it is active or not or something like that guys then we cannot uh as long as because we have some is active here so if you'd like to prevent also like those active one or inactive one then we would like to prevent but if you were if you want more to be more unique even though if it is uh inactive or something like that then we would like to prevent it uh that that one is more uh okay guys because we don't want later on um more uh junk data that we would that we stored in our uh mysql table so in this case we would like to prevent even though if it is just uh inactive is false or the user just play around and then or in the or halfway they will uh uh don't want to what they call this continue with the registration or something like that it's a it's a common case guys soon so that one is a no worries one but when they try to register it again uh probably the email email address there uh which already existed so we want a very unique email address and and then the username as well because later on um this email here this one is a very useful when we have some kind of a email notification or some kind of an alert so or a password reset this is a very unique must be unique guys otherwise two email address with a different username it's not a good thing guys because when you when the user requests for the password reset or something then both the users can receive those uh emails so we would like to prevent that to happen in our um system guys so well the best the best thing is we would like to block them with the duplicate email and then of course the username these two is a very critical guys and of course the password the password is already encrypted so we don't want to worry much only this email address and the username it should be a very unique one we don't want to rely further on the mysql uh table to prevent uh actually we can do that here in the mysql level but i don't want to pre uh i i don't want the duplicate um memory usage for example for this mysql if you want to prevent that one as well uh like a unique one we don't want to why they call this burden our sql server with regards to we don't want to load more tasks to the to our mysql database yes we would like to prevent that one because uh we we have we don't have much uh memory in our database of course so if you have more but the good good practice there is don't give much burden to your database um as much as possible don't create much uh stored procedures there uh we have some so many kinds of thing guys for this uh like the store procedures um like um what do you call this um we don't want this in our uh topic as well so if i advise you we have this experience we don't want to burden a lot in our database we when we can we do do it in our coding is more better and a more faster one guys otherwise if you improve if you want to create a very complicated or so much of linking there in our mysql we don't want to to do that because it's later on it will be much lower in our database so all those uh linking one like all these are primarily linked to each other we don't want to i don't want to encourage you to do that because uh the one later part uh you will have a big problem okay so in your database especially when it's a lot of data there millions there so we have that the experience as well so i don't want to for those uh starter students they're out there listening uh we don't want to prevent more what they call this the the don't do uh much linking in our database like the primary here although we have the primary but we don't want to link to another table okay so we don't want to interlink together okay so we we don't want that guy so just uh just a quick reminder and um is a actually it's a experience that uh you don't want to repeat for your own experience as well but if you want then you just go on with along with it guys so but later on uh you will have a problem uh managing your uh big database okay so this one is just a it's a golden experience case that i would like to share it with you most especially those students out there who are listening or just started learning programming okay so with mysql or any kind of database guys okay so we will uh this one is we would like to change only guys the email should be the field name there is the email address okay so then we would like to change this as well as an email okay just change a little bit guys duplicate username so [Music] probably we can now it's okay so we just changed the name here okay so we will copy same thing here for this one is the email part so we will group together okay so group together here below guys check if the uh email address is available or not okay so email is not available okay please try again like that you guys can okay so email so we also have this kind of thing now okay so probably it should be okay now so we can prevent any duplicate username there so we would like to run it again at the moment we don't want to build the wasom guys because we are working directly with a go program here go scripts uh that doesn't involve with wasam so as you notice that we don't build with wasam because this one is our built-in goal here so we don't want to do that unless we are working with the for the wasam here so at the moment we don't uh export because we don't want we never touch this code at the moment here so okay so we will would like to continue on okay so but i encourage you guys to to work on this um to work on what some guys webassembly because this is the future of web development so if you are stick around or still in these what they call these ajax pose or something like a javascript or any kind of java of javascript framework there probably you can still use that for how many years but i would like and i highly recommend for you to work on the web assembly because this is the future of the what they call the web web development right now the major thing is the major uh programming language there that supports uh webassembly which is a go of course and then um rust and then c plus plus uh c something okay so these are lucky for us because if you have learned just learn this golang uh most especially if you are building um a highly secured web web page or something web development here guys this one is the best for us because we we don't want unwanted users to just simply view source and then check your ajax post there the url or something like that then it's totally exposed as you notice in our previous uh discussion that this web assembly is uh you cannot you cannot view source guys as what i mentioned here because it runs your view source we don't have the any ajax post here instead we have this uh wasam this uh that wasam file that serves as our uh everything then that the ajax post is there so we don't see any uh logics in our pages there as you can see it's a very bare and plain html all those elements okay so so these are all the things only this is the benefit for us guys uh we most especially if you have uh software that you want to bring over to the browser side like uh nowadays there's many like the games there the online games they are all using awesome uh all those are utility tools like uh like what they call this uh like adobe something like uh editor the photo photo fee or something uh you want to edit uh like the image or something like a photoshop online that one is a it's a web assembly guy so all the thing there most likely the uh all the traditional softwares the classics offers are now bringing bring it over to the browser site uh for us to easily access it without the need for the installation so this is the the thing and the future they are keep developing this webassembly because they want to prevent any software installation in the future so okay so i would like to i would like you to use and highly recommend to use the webassembly okay so we will continue on guys we will just refresh and then now is a running we would like to prevent um any duplicate we don't want to erase yes so we just want to try this uh i'd like to copy this just to prevent the thing okay so i would like to do it like harlequins then i will try to we'll try to add another domain and i mean the username here so these margins is the username is there it's not exists but we reuse these bullets at itrepublic.com so we would like to test that email is not available okay now it's totally working guys but if you want to put like admin here let's see okay the username also is in effect okay but if you want to change that admin one so the email now is uh taking place uh validating this user okay i mean this uh email address but if i change a new email address let's say is just uh just try different one uh here we don't have the user i mean the admin that this kind of email guy so we would like to add now okay successful so totally is an admin one and then uh admin dietary republic so okay so totally we can register guys and then we have successfully implemented the uh to prevent this username and the email is these two fields are more critical for us for any uh user's authentication guys because in the long run um we will have headaches when you allow duplicate email address during the registration process okay so this one is very important because we would like to notify this user when the user requests for any password reset or something like that it's okay so this is the primary email address later on when we go along with the dashboard there then the user can log in then we can change the password there again so just change the password all these things or you want to change or you want to change uh if the user change the username or username we don't want to allow the username to change yes it should be the unique one but um okay so because if you allow to change the username is a lot of uh it's like it's good good as new thing guys so we don't want that we can change the email address only that one is a possible guys and then we would like to validate it again or something like that so we would this one is uh we have done this um basic validation at the moment guys so okay okay that's all for today guys and i hope you enjoy our tutorial series here in markets code and i hope i impart with you some knowledge there so most especially our students there and or just started or learning uh golang with the mysql database and of course this one is our future project that we can reuse once we have done this yabby series guys we will publish this into our github there and then you can go get this package and then if we fully tested and uh properly okay then we can reuse this in our project uh we just go get and then just uh installation uh use it in your golang project or go web development or something like that something like that guys okay so uh let's see we can continue on uh with this and then uh probably in probably in our next uh the tura series here tutorial video here as a continuation of this yabby series we can create uh the email address guys i mean something like the user register and then we will send automatically an email to the certain user with the corresponding email address of course and then we will try to receive that and the user will receive the email confirmation and then there is uh something like the layout of the email that we would like to receive and then they just click on that confirm button or confirm registration something i think so we will uh definitely we can uh we will have that um in our next video guys okay so for those people who are not subscribing yet please consider subscribe to my channel here in malacanang school so that you have more videos like this and to honor uh my work here in harlequin's code so okay so if i have a spare time guys i will have uh to i will probably share the codes here uh okay so uh for those people who are um we'd like to visit our github our mahalakans code github there you can get the latest code i will upload by batch okay for those people i will just upload by batch how many series there i already uploaded the the previous one uh so uh this recording this recording now is not yet uploaded so we will be having some few series there like a 10 series then i would like to upload it in our github so okay so uh just uh download the source code the latest source code that we are working here and then you can share it subscribe guys to my channel to honor and my work here in marlingan's code okay thank you so much for watching my video can you subscribe to my channel and see you in my next video guys may god bless us all thank you and bye bye keep safe everyone
Info
Channel: Maharlikans Code
Views: 160
Rating: undefined out of 5
Keywords: go, golang web development series 25, golang web development course, web development with go, golang tutorial, learn to create web applications using golang, building scalable web apps in golang, golang good for web development, golang http user authentication, golang http authentication, golang user registration, golang authentication microservice, golang session authentication, golang webassembly, golang mysql, golang mysql tutorial, golang sql
Id: VJk9EYysTEc
Channel Id: undefined
Length: 37min 17sec (2237 seconds)
Published: Tue Dec 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.