Welcome back.
OK, I hope you tried to solve the exercise.
Now I'm going to solve it without using the cool features of God that you didn't learn about yet.
Normally, I would do this in a different way.
However, at this level, it's better to use the features that you learned so far.
All right.
Let's get started.
That's at the second username and password inside the constant declaration here.
I'm going to add one more user, Konstanty user to.
In lunch, then I'm going to add the password constant for a second user pass to.
Eighty seven, nine.
OK.
In this if statement, I need to check the username of the second user like this, you not equals the
user to.
OK, so if what user names are not correct, then I will display another.
Otherwise, it will execute this massive branch here.
This means that both usernames are correct.
So here I'm going to check whether the second password is also correct like this.
Peanut equals to pasta here.
I'm simply telling that don't grant access if both passwords are not correct.
OK, let me try this first, I'm going to pass the username and the password for the second user.
In 1879.
Cool, it works.
Now, let me try the first user's password instead, delete this and let's stop 1888.
There's also works, right, but it shouldn't have worked, it's because now the second user can access
to the system by using the first user's password.
It's like you're accessing your email application, using another user's password, and they can also
access yours by using their own password.
So this is not good.
Let's fix this now.
OK, the problem is in this line.
So it doesn't matter which user's password I'm passing to the program.
It just checks whether the past password matches to the first users and the second user's password.
So that's the problem.
To solve this, I need to add another condition to this booth expression for now.
Let's remove the second check from here.
OK, so first I need to check for the first user like this.
You equals to user.
Then let's make this more simple by changing does not equal operator to equal operator like this.
Since his last expression checks for the correct user and password, so I need to move this access,
OK, from here to here, then I also need to move this air password from here to here, OK?
So here first is checks for the first user, and if it's the first user, then it checks for it's password.
So if the user is the first user and the password is the first user's password, then it grants access.
Now, this at another check for the second user this time.
First, I'm going to type a logical or operator, then in a new line, I'm going to check for the second
username like this.
And if it's correct, then I'm going to check for a second user's passwords like this.
So here, if it's the first user and it's password is correct or if it's the second user or if it's
password is correct, then the program will grant access.
But if neither of them is true, then it will execute this as branch and it will say that the password
is incorrect.
OK, as you can see here, you and your line with an operator, then you can type the second expression
just below it.
OK, let's try this first, let's try it with the first user, Jack.
Now, let's use the second user's password, 18 seven, and I call this time, it didn't grant access,
as you can see now, I can't use the other users password.
While security improvements indeed look now, this time the correct password for the first user.
Access granted, cool.
Now, let's do the same check for the second user.
That the past the second user name with the first user's password, it shouldn't work.
Right.
All right, it didn't good.
Now, this time, the correct password for the second user, finally.
Access granted, good, OK, so far, so good.
However, this court looks somewhat ugly, right?
This bull condition looks complex to me.
Let's make it simpler.
I'm going to add another Assif branch here like this.
Then I'm going to cut this bull exploration from here.
Then I'm going to move it here as the condition for this elusive branch.
And I need to remove this logical or Oprey there as well.
And lastly, I need to duplicate the access granted message or the massive branch.
OK, I think now it looks better, I needed to duplicate the access granted message, that's OK.
Sometimes for more readable code, you may need to duplicate the code.
OK, normally I could do this using a function that would not be duplicated, but you'll see how to
do that afterwards.
OK, let's try it one more time.
That's right, a second user.
The first user's password, again, he should, in fact.
Good.
It doesn't work now this time.
That's correct, password for the second user.
Access granted.
OK, now let's pass the first user with the second user's password.
Cool doesn't work either.
Finally, this past the correct password.
OK, access granted, cool.
As you can see as of branch here, acts like a logical or operator, right?
So this court and the previous court acts like the same.
All right.
So for now, you built a user password protected command line program, military level security indeed.
I'm just kidding, of course.
OK, you should be proud of yourself.
Thank you for watching in the next hour.