Welcome, happy assault, the challenge, if you didn't, please do so after this course, you won't
remember anything about school.
You can only learn it if you work on it.
All right.
Now let's take a look at the solution.
First thing I need to do is to get the user name and the password from the command line.
Normally you shouldn't get this from the command line.
Operating systems can record this kind of information, but for now, it's OK.
OK, let's first store the oil that are extreme slice into a variable because I'm going to use it a
lot.
Like I said, this program expects a username and password, so there should be three arguments, right?
Remember that the first argument is the path to the running program.
So I'm going to check whether there are three arguments or not like this, if land are not equal to
the three.
OK, so if there are less than three arguments that display a usage message like this one, I'm going
to call Princella.
Then I'm going to type usage username.
And password.
OK.
And let's just return from the main function, directly visible, terminate the program because the
program ends, then the main function returns.
It is the only function that executes a program.
That's the reason of that.
OK, let's try it now.
I'm going to type go around mean that go OK, as you can see, the program prints the usage information
because I didn't provide any input to it.
This past Twitter user and a password now like this.
Go around in that go, Richard Pyper OK, now it doesn't say anything good, this is good because since
there are three arguments inside start slice.
So the if statements block is an executed.
All right, let's continue now, let's save the username into these ueber so it's the second element,
that's why I'm going to get it from the first element.
Now I'm going to check for a single user, Jack.
OK, this first check, whether the user is Jack or not like this, if you.
Not equal to Jack.
OK.
And if the user is not Jack, then display an error message like this and will use Prenter for that.
This first type exists tonight for.
Person Q This will wrap the string inside double cuts and new line.
OK, then I'm going to pass the other one to display the user name again.
OK, now let's run the program again.
It says that the user, Richard, isn't allowed to pass good, let's pass Jack instead.
Now, it doesn't say anything, it's because the program has recognized the user.
OK, let's continue now.
Let's save the passwords into the P variable.
OK, as you can see, this is a short declaration.
ARC's one, here is the username and ARC's two.
Here is the password.
So you start the past user name and P stores the past passwords.
OK, now let's check whether the password is equal to eighteen eighty eight or not, just using a not
equal operator like this elusive.
P, not equal to 1888.
OK, this as if Branch will only run if this first condition is false, right?
So this as if will run if the user is correct.
But if the password isn't correct, then let's display an error message again like this.
Invalid passwords for the user new line, then I'm going to pass the user, OK?
All right, that right now, check by bring in it prints, this was a wrong password for the user Jack
crew.
Normally this is a security flaw to tell about this, because you shouldn't tell that there was a user
with the same name or not.
So please don't try this at all.
OK, now let's try it with the correct password like this.
Jack 1888.
The program becomes silent again is because it has accepted the password nahles and asked Branch to
this if statement to tell that access is granted like this as printf access granted to Q OK and the
user.
Right.
So the program first checks whether the username is equal to Jack, and if not, then it drops the first
if statement.
So if it equals to Jack, then it checks the active branch.
So if the password isn't equal to 1888, it runs to Altuve branch.
And lastly, if the password equals to eighteen eighty eight, then it means that both the user and
the password are correct and it runs to as French did, is simply how it works.
OK, so let's run the program again.
Well, the access is granted, Cuke, I mean.
What do you think can improve this program further?
Maybe so this trial factoring this program a little bit by using constants now.
I know that these error messages won't change, so it's better to put them into Constance.
As far as Copiah, the usage message from here like this and this type here usage instead.
Dallas create a constant like this constant usage is posted here.
OK.
OK, now do the same thing for the existing right message.
I'm going to cut it from here.
I'm going to change it to our user, then I'm going to declare a new constant.
Names are you?
I'm going to pass the value here.
OK.
Right now, do the same thing for the incorrect password message.
I'm going to just get it from here.
SPW, the OK.
Let's declare a new constant basis here.
All right, and now let's change the access granted message that constant again like this.
OK, cut it from here and let's change the axis, OK?
And declare success, OK?
This bastard here.
OK, good.
And lastly, let's refactor the user and password into constants.
OK.
User.
And Jack.
Password.
OK, let me right now.
All right, it displays the usage cool.
Let's give it an incorrect user, for example, my name.
One, two, three, four.
It works right now.
Let's give it a correct user, but an incorrect password.
Check.
One, two, three, four.
All right, good.
It works.
Now, let's pass the correct username and password.
Eighteen eighty eight.
Cool, everything works right there.
So for now, see in the next lecture.