‫Welcome back.
‫And this video we are going to solve the challenge from last lecture.
‫And I hope you try to do it yourself and you fix it or you solve the problem.
‫So let's go ahead and create a login system and a well register system.
‫We need first of all to register before we can log in.
‫So let's create two methods to do that.
‫One of them is going to be public void or actually registration could go right.
‫It can be void and register.
‫And then in here we want to do all the registration, but as we want to use this method inside of our
‫main method, we need to make it static.
‫So in here we need to do certain things.
‫First of all, we need to check or we need to tell the user what to do.
‫Console right line.
‫Please enter your username and then the user can enter his username and we want to store that username
‫somewhere at least for the runtime.
‫So we need to create a new variable here, which I'm going to call static string username.
‫And in here we set the username as whatever the user has entered.
‫So console dot read line.
‫Next, I want to do the same thing with the password, so I'm going to copy the code and I'm going to
‫replace that with password and I'm going to replace this.
‫Username with password as well.
‫Therefore I will need a password variable.
‫So static string password.
‫And here of course we won't need the username anymore.
‫We will need the password.
‫So first we check for the username, then we check for the password.
‫Once that is done, once the user has registered, we want to tell him registration has worked.
‫So registration, complete it.
‫And then maybe even another line where we simply have a bunch of dashes just like that.
‫All right.
‫So that's how we can register the user.
‫And now let's create the login method, public static void login.
‫And that one will be quite similar to the register method.
‫So I'm just going to check for the username first.
‫And in here I have first ask for it and then I check if it actually works.
‫So if username is equal, so double equals sign whatever the user has entered.
‫If that's the case, then go ahead and run the following code.
‫Check for the password.
‫So then go ahead and ask for the password and check if password is equal to whatever the user has entered.
‫Now we can go ahead and write to the user that logging in has worked.
‫So red line login successful and if it didn't work, so if the user has not entered the correct value
‫then we'll tell him.
‫Log in failed.
‫Wrong password restart program.
‫And the same thing.
‫We're going to tell him if it didn't work to log in because he didn't enter the correct username.
‫So in here we simply say console right line login failed, wrong username restart program.
‫In our case, we don't have wild loops yet, so we don't have the capability of running while loops
‫so the user can log in again or try to log in multiple times.
‫So we're just going to solve it that way now.
‫So we say restart the program.
‫So we have an if statement where we check.
‫Did it work?
‫So did the user enter the correct username.
‫If he did, then we ask for his password.
‫If he entered the right password, we simply say, All right, cool, you're logged in.
‫If you didn't enter the right password, we say, login failed and the password was incorrect.
‫By the way, if he failed to enter the right username, we run into this LX statement and we simply
‫say, okay, failed to log in.
‫Now what we can do is we can go ahead and register and then we can log in.
‫And finally we need to do console, right, to do anything so that at least something is written onto
‫the console.
‫All right.
‫So we had to create global variables here, and we haven't covered that in too much detail yet.
‫But we need to create them globally because we need to use them in multiple methods.
‫That's something that is based on scope.
‫So we have covered scope and well, that's pretty much what it's really about.
‫So let's check it out.
‫Let's run the code and see if it works.
‫So please enter your username.
‫I'm going to enter Dennis and your password.
‫Password one highly secure password now registration complete.
‫Now please enter your username.
‫I'm going to enter Dennis and I'm going to enter a wrong password and it says login failed wrong password.
‫Restart the program so I'm going to close and start again.
‫Please enter username then is again password one.
‫Now I'm going to type in an incorrect username login failed wrong username reset program.
‫All right, I'm going to do that.
‫And now let's enter it correctly.
‫So then is password one then is password one.
‫Log in successful.
‫Great.
‫And now I can start hacking.
‫All right, so now you know how to create a very, very basic login screen or register and login screen.
‫Of course, we don't store the information yet, at least not longer than runtime, but we will see
‫how to store data permanently later on.
‫Great.
‫I hope you could manage to build something similar to that and could test it.
‫And well if not, no worries.
‫Try to shut this down or close this and just try to rebuild it tomorrow.
‫So give yourself some time and just try to do yourself based on memory and based on what you have learned.
‫So just try to do that tomorrow.
‫Great.
‫So I'd say that's a good start for a login screen.
‫And in the next video, we're going to go ahead.
‫So see you there.