The Login Logic

Tim Buchalka's Learn Programming Academy
A free video tutorial from Tim Buchalka's Learn Programming Academy
Professional Programmers and Teachers - 990K+ students
4.5 instructor rating • 50 courses • 990,324 students

Lecture description

In this lecture you will learn about booleans, if else statements and how to know if a string is null or empty, to set a basic login in functionality

Learn more from the full course

The Complete Xamarin Developer Course: iOS And Android!

Build Cross Platform Android and iOS apps with Xamarin Forms, Xamarin Classic, Azure Mobile App Services, Rest and more

29:18:29 of on-demand video • Updated August 2020

  • Create native Android and iOS apps that share up to 100% code
  • Apply for junior mobile development positions (Android and iOS)
  • Increased career options as a Multiplatform developer
  • Learning Xamarin opens up opportunities to build Windows Desktop, Windows Store, Mac, and even smart watch apps that share the logic of your iOS and Android app
English [Auto] We haven't really designed a logging page for application. It's time for us to add some functionality to the log in page so we can show it to usurp as opposed to logging into the main section of the application. I mentioned in the previous lecture that we are not just going to evaluate the database but we do want to evaluate if at least the user has written something inside of both entries to be able to do that. We're going to start working a bit with C-sharp. And of course we're going to start working inside of the code that is going to execute every time they log in bottom is clicked to be able to evaluate if certain the string is no or if it's empty. We have a very handy method at our disposal through the string type the string type is precisely the type of the text that is some of the entries and the string contains an evaluation that will return true if this string that we're evaluating is know or if it's empty to access this evaluation we can go right down the street which is the type dot and start writing East no or empty is not or empty again. He's going to return true when the string that we evaluate either is no. Meaning that it doesn't really exist or if it exists but the value sent. For example when the user has written anything inside of the entries so that stype entered town or keywords to be able to access the full evaluation and then in parentheses is where we want to parse the value that is going to be evaluated. Notice that Visual Studio allows you to know what value this evaluation is expecting. In this case history and we want to access this string from one of the entries but remember that to be able to access the values from the properties of the entries or any of their element for that matter we need to name those elements. So let's navigate back to the main page to sample file and set some names to both entries. The first entry for example is going to be called e-mail entry. And the second entry is going to be called password and 3. So now that both entries have names we can access them from C-Sharp so we can start typing here e-mail and tweet and then access the text property. We can do that through dot text and then we have to add a semi-colon at the end. So this is going to evaluate the text instead of the e-mail and to the east not were empty. I would turn to if it is false if it isn't but we need to assign that through or forth to something. So we can later evaluate it. I am going to create a boolean variable in here and this is how you create variables you define the type of the variable and then you define a name. In this case is the mail empty. And I'm going to assign it to whatever this evaluation returns. So with this new variable that is going to be Boullion and there is going to be call is empty. We're going to have to use the text inside of the email and it is empty or no and false. If it isn't and then of course we're going to meet the exact same thing for the password entry so I can do is create another boolean variable that is going to be these passwords empty. And I want to assign it to again stream Dot were empty. But in this case what I want to evaluate is a text inside of the parse words into something like this. And so I now have these two variables whether or not the text instead of the entries is not empty. The next thing that I have to do is know if any of this is empty because if at least one of these streams are empty then the user can't log in. But if both of these at least have something on them then the user can begin to make this evaluation. I will need an if statement. This statement is going to exactly evaluate one value against an order and execute when the evaluation is true. For example I could evaluate the is email empty is equal to through this would mean that the text instead of the e-mail entry is either know or is empty. So the user didn't write anything inside of it. And so the user shouldn't be able to log in. And if this is true then the block of code that I defined instead of this bracket's is going to execute if it isn't true then I do need an else statement. And they also need some brackets inside of here. This is the entire If Balcer statement. If the evaluation between the parentheses is true then the block of code for the if statement is going to execute. If it is false then the block of code for the else statement is going to execute the if statement is optional meaning that the if can exist by itself. But the ALSA statement cannot exist without it. If so here I'm only evaluating if the email is empty. But what happens if the password is empty. I need to know if it is empty as well. What I can do is add and or evaluations here and I can do that with these doggo vertical lines and evaluate after the very Collines if these parts were empty equal to the or evaluations here were return true if at least one of these evaluations is true. So if the first of all you ational is true and the second is false the OR will still return True Meaning that that EAV block of code is going to execute. If the solution is false and the second one is true again the or will return true. So this block of code will execute and if the first is true and the second is true the board will still return True Meaning that this block of code will execute. The only time the or evaluation side of this if statement we return false is when both of the evaluations are false. In which case the block of code instead of the else statement will execute. Now there is a way in which we can minimize the code that we are Graveney here and that is to remove this evaluation to compare a boolean property to another Boullion because this evaluation is already a boolean. These values are really a boolean. So there's no need to evaluate against another boolean to return a boolean because it already is a boolean. So I can remove this if this was already true evaluating it against true will return true. And if it is false if only to meet again. True we return false. So there's no need for that evaluation because this already has the value that we need to be able to test this out. I am going to add a couple of break points here which will allow me to know which book of code is going to execute in certain scenarios what I'm going to do is going to roll my application on an android simulator and click the bottom on different scenarios to evaluate what block of code is going to execute. So here on the Android emulator really to test what block of code is going to execute when certain values are created instead of the entries or if there is no value at all. For example let's check what happens when I click again. We are writing anything in of the entries. But is that the first breakpoint was hit. So let's get back to Visual Studio and evaluate what has happened. The first thing that we can establish is that this is email MT's going to be true because we didn't write anything inside of the e-mail entry. And the same is going to happen for the passwords because we didn't greit anything there either. So this is going to be true and this is going to be true meaning that true or true is going to be true and that statement is going to execute we can we can continue to make another evaluation that can be entered in later against let's write something down inside of the e-mail address and click on the log in Boston again. In this case the e-mail is not empty but the password is meaning that false or true still returns true. Which makes these if block of code to be executed. Now let's go we can continue and evaluate another thing. What happens if we do not have anything inside of the e-mail but we do have something inside of that password and click the log in but still Dave statement is going to execute because true or false is still going to return true. And finally let's continue to evaluate what happens when we have something written down on both entries. Let's say you can log in and notice that now it is the else clause the one that is going to be executed because both it is in empty and that is passed with empty values are false meaning that false or false is false. And so finally the statement or the else block of code is executed. Now that we have perform this evaluation and then we know that if the else block of code is executed in means that the user did greit both the email and the password in the next letter will go into the functionality for us to be able to navigate to another page. Right from this block of code.