WEBVTT 00:00:07.350 --> 00:00:09.600 So far we have made some really good progress. 00:00:09.600 --> 00:00:14.690 We have created code which allows users to sign up and log into our web sites. 00:00:14.880 --> 00:00:20.730 Now many users don't like to be asked their email address and password every time they come back to 00:00:20.730 --> 00:00:21.820 the Web site. 00:00:21.840 --> 00:00:23.160 So what they do. 00:00:23.160 --> 00:00:26.440 They check the Remember Me box while logging in. 00:00:26.760 --> 00:00:30.330 So we need to write some code to activate that feature. 00:00:30.660 --> 00:00:38.070 OK so if you go back to the code we have written before we checked if the Remember Me box is not checked 00:00:38.260 --> 00:00:40.830 and then we echoed success straightaway. 00:00:41.070 --> 00:00:41.930 OK. 00:00:42.360 --> 00:00:48.650 Now if the remember the box is checked we going to write some code for that. 00:00:48.690 --> 00:00:53.500 So we have covered the logic of the code earlier but very briefly what are we going to do. 00:00:53.520 --> 00:00:57.710 We go to create a couple of variables but we're going to generate randomly. 00:00:57.860 --> 00:00:58.560 OK. 00:00:58.730 --> 00:01:02.570 And then we can test all those variables in a cookie or the user's device. 00:01:02.630 --> 00:01:07.530 Also we're going to store those variables in the Remember Me table. 00:01:07.770 --> 00:01:14.610 So when the user comes back we go to much or ever variables we retrieve from the cookie or their device 00:01:14.940 --> 00:01:17.870 with the variables that we find in the database. 00:01:18.000 --> 00:01:22.670 OK and if we how much we're going to log that's usery. 00:01:22.770 --> 00:01:23.040 OK. 00:01:23.040 --> 00:01:25.300 So let's go ahead and write some code. 00:01:25.320 --> 00:01:29.330 So first of all we're going to create these two variables. 00:01:29.540 --> 00:01:30.560 OK. 00:01:30.900 --> 00:01:36.890 So are you going to use a function called Open SSL. 00:01:37.060 --> 00:01:45.350 Ok random pseudo bytes as we do before. 00:01:49.160 --> 00:01:55.810 And this function takes as a barometer the number of bytes that you would like to generate. 00:01:55.830 --> 00:01:59.660 OK so let's go for 10 bytes for the first variable. 00:01:59.760 --> 00:02:05.760 Also if you want you can convert the outputs of the function which is in binary. 00:02:05.760 --> 00:02:08.250 You can convert it to a decimal. 00:02:08.330 --> 00:02:12.920 OK the function for that is binary to ex-head decimal. 00:02:13.110 --> 00:02:15.040 OK we have used this function before. 00:02:15.330 --> 00:02:17.170 You must be familiar with it. 00:02:18.180 --> 00:02:23.230 And LS generates the second variable in the same way. 00:02:23.460 --> 00:02:29.460 OK for a second variable you can go for 20 bytes if you like or. 00:02:30.460 --> 00:02:31.690 OK. 00:02:32.550 --> 00:02:36.680 Now the next step is to store these variables inside a cookie. 00:02:36.840 --> 00:02:44.190 OK so the next step. 00:02:44.820 --> 00:02:51.190 So to create a cookie we can use the function set cookie. 00:02:51.470 --> 00:02:59.460 OK so this function is going to take a few promises so the first problem is going to be the name of 00:02:59.460 --> 00:03:00.060 the cookie. 00:03:00.150 --> 00:03:00.730 OK. 00:03:00.930 --> 00:03:02.520 So let's go for 00:03:06.390 --> 00:03:10.930 remember me. 00:03:10.930 --> 00:03:12.510 All right. 00:03:12.510 --> 00:03:17.430 Then the second parameter is going to be the value of the cookie. 00:03:17.430 --> 00:03:19.750 So for now let's go for a variable. 00:03:19.770 --> 00:03:25.600 Let's we're going to call cookie Valley and we're going to come back to this in a bit. 00:03:25.740 --> 00:03:26.510 Okay. 00:03:26.970 --> 00:03:35.150 And then we go into the expiration dates or expiration date and time for our cookie. 00:03:35.430 --> 00:03:36.310 Okay. 00:03:36.780 --> 00:03:41.310 So let's say would like the cookie to expire 15 days from now. 00:03:41.400 --> 00:03:41.960 Okay. 00:03:42.150 --> 00:03:44.220 So we're going to start from the current time. 00:03:44.280 --> 00:03:47.210 So we're going to go for the Unix timestamp. 00:03:47.460 --> 00:03:47.740 Okay. 00:03:47.760 --> 00:03:53.380 So the current time can be referred to using the time function. 00:03:53.670 --> 00:03:54.370 Okay. 00:03:54.750 --> 00:03:59.610 And then we can get to that 15 days and that needs to be in seconds. 00:03:59.640 --> 00:04:11.030 So 15 days is 15 multiplied by 24 days 24 hours multiply by 60 Minutes multiplied by 60 seconds. 00:04:11.070 --> 00:04:11.730 OK. 00:04:11.730 --> 00:04:17.200 So this number is going to give us the number of seconds for 15 days. 00:04:17.280 --> 00:04:23.470 So that's going to be 1 2 9 6 triple 0. 00:04:24.180 --> 00:04:33.070 Okay now let's have a look at the value of our cookie. 00:04:34.320 --> 00:04:40.440 So it is going to be the outputs of a function which I'm going to call EF 1 and this function is going 00:04:40.440 --> 00:04:46.580 to be of the two variables that we generated earlier. 00:04:47.070 --> 00:04:47.590 Okay. 00:04:47.850 --> 00:04:52.400 So we're going to define this function in a bit. 00:04:52.440 --> 00:04:52.930 Okay. 00:04:53.250 --> 00:04:56.730 So let's define dysfunction. 00:04:57.090 --> 00:04:59.310 Okay. 00:05:00.460 --> 00:05:06.370 And take a couple of promises a B. 00:05:06.740 --> 00:05:08.980 Okay. 00:05:10.980 --> 00:05:15.960 So this function needs to fulfill a couple of requirements so the first one this function should be 00:05:15.960 --> 00:05:17.160 very easy to guess. 00:05:17.160 --> 00:05:18.120 Okay. 00:05:18.150 --> 00:05:27.450 Also we need this function to be more or less practical in a way that will allow us to retrieve the 00:05:27.540 --> 00:05:28.560 variables. 00:05:28.650 --> 00:05:29.660 Okay. 00:05:33.570 --> 00:05:35.700 From the value of our cookie. 00:05:35.780 --> 00:05:36.310 OK. 00:05:36.330 --> 00:05:37.920 So if I go for example for 00:05:41.520 --> 00:05:43.440 a dot 00:05:48.240 --> 00:05:54.180 B OK let's me as we just concatenating the two variables. 00:05:54.210 --> 00:05:54.670 OK. 00:05:54.840 --> 00:06:03.520 If we do this is going to be very hard to guess what a is and B is from the value of the cookie. 00:06:03.660 --> 00:06:08.840 OK so there is absolutely no way to retrieve a and b from the value of the cookie. 00:06:09.030 --> 00:06:18.430 But if we concatenates a and b and we place a comma in between. 00:06:19.080 --> 00:06:27.660 OK like this then from the value of the cookie we can actually write some code that will look for that 00:06:27.720 --> 00:06:35.290 coma and then he will tell us that's the variable a is whatever is on the left of the comma. 00:06:35.400 --> 00:06:40.570 And very we'll be is whatever is on the right of the comma inside the value of the cookie. 00:06:40.840 --> 00:06:49.220 OK but to make the function a bit more complicated I'm going to store the second variable OK or generate 00:06:49.230 --> 00:06:51.900 the second variable in binary. 00:06:51.900 --> 00:06:59.260 So we're going to get rid of the function converging to exit a symbol OK. 00:07:00.810 --> 00:07:09.800 But when concatenating the two variables inside our function I'm going to convert variable be to X it 00:07:09.800 --> 00:07:11.190 is all right there. 00:07:11.420 --> 00:07:11.670 OK. 00:07:11.670 --> 00:07:15.450 Just like this. 00:07:15.690 --> 00:07:18.590 All right. 00:07:18.870 --> 00:07:24.440 Now let's see the results of this in a variable c.. 00:07:25.710 --> 00:07:26.510 OK. 00:07:26.850 --> 00:07:29.080 And then let's return. 00:07:29.220 --> 00:07:33.040 C OK. 00:07:33.270 --> 00:07:40.770 So to summarize function f one is going to take a couple of strings and then he's going to return C 00:07:40.830 --> 00:07:43.430 which is the concatenation of a. 00:07:43.530 --> 00:07:45.960 And the conversion of B to exit is simple. 00:07:46.040 --> 00:07:48.780 Ok with a comma in between. 00:07:48.780 --> 00:07:50.410 All right. 00:07:50.880 --> 00:07:58.050 And if you want the inverse function which is supposed to give us a and b all you do is take the results 00:07:58.320 --> 00:08:03.930 look for the comma and then on the left hand side you find the variable a right hand side. 00:08:03.990 --> 00:08:07.170 You'll find the very will be in X it is small. 00:08:07.260 --> 00:08:08.720 OK so it's to find B. 00:08:08.760 --> 00:08:11.810 We just need to go back from X it is simple to binary. 00:08:11.990 --> 00:08:12.470 OK. 00:08:12.510 --> 00:08:15.070 Which we are going to do later in the Remember file. 00:08:15.260 --> 00:08:16.170 OK. 00:08:16.290 --> 00:08:18.140 All right so we've got now our cookie. 00:08:18.210 --> 00:08:18.850 OK. 00:08:19.060 --> 00:08:22.190 And we told the right value inside the cookie. 00:08:22.200 --> 00:08:28.980 Now the next step is to run a query which is going to store these two variables in the Remember table 00:08:28.990 --> 00:08:29.180 . 00:08:29.370 --> 00:08:30.220 OK. 00:08:31.020 --> 00:08:32.490 So it's going to be the next step 00:08:32.490 --> 00:08:39.500 . 00:08:43.320 --> 00:08:44.600 Now going to. 00:08:44.790 --> 00:08:47.820 The query inside a variable as you will. 00:08:47.970 --> 00:08:48.780 OK. 00:08:49.530 --> 00:08:57.010 So the query is going to store a record in the Romary table. 00:08:57.090 --> 00:09:07.020 OK so that corresponds to the columns also as we cater one if two of us has vacated 2 then the user 00:09:07.020 --> 00:09:10.230 id then the expiry date and time. 00:09:10.320 --> 00:09:13.110 So the syntax is going to be hours following. 00:09:13.110 --> 00:09:23.430 So we're going to insert into the table so the tables name is remember me. 00:09:25.290 --> 00:09:26.080 OK. 00:09:26.520 --> 00:09:35.560 And then we're going to have the columns where we're inserting values. 00:09:35.620 --> 00:09:38.580 OK and then values 00:09:41.320 --> 00:09:45.830 and then the corresponding values for those columns. 00:09:46.000 --> 00:09:53.310 OK so the columns are going to be as following so authors because I because. 00:09:53.930 --> 00:09:54.200 One 00:09:56.740 --> 00:09:57.950 . 00:10:00.270 --> 00:10:01.860 Between single quotes like this 00:10:08.980 --> 00:10:15.930 then if two of all is vacated two thirds 00:10:19.140 --> 00:10:20.460 and then the user id 00:10:22.460 --> 00:10:26.100 a and then 00:10:30.240 --> 00:10:33.350 expires OK. 00:10:33.360 --> 00:10:38.390 And then the values we're going to use variables for this. 00:10:38.430 --> 00:10:39.320 OK. 00:10:39.990 --> 00:10:42.660 To make our code easy to read. 00:10:42.690 --> 00:10:45.800 So we're going to have all the advocates for one. 00:10:46.250 --> 00:10:48.380 OK. 00:10:49.680 --> 00:10:55.090 Boy to all those Jews who are going to create a very well innovate. 00:10:55.140 --> 00:10:56.000 OK. 00:10:56.160 --> 00:11:04.800 We're going to call if to of all things be catered to and then for the user id we're going to create 00:11:04.920 --> 00:11:09.120 a variable as well that's. 00:11:10.710 --> 00:11:19.190 And then the expiry date and time we're going to create also a variable for that unless it's expiration 00:11:19.210 --> 00:11:20.360 . 00:11:21.440 --> 00:11:24.460 OK. 00:11:25.740 --> 00:11:30.990 So as we said earlier in the logic section we're going to keep the first variable as it is. 00:11:30.990 --> 00:11:36.120 And we're going to stories as it is on the table while the second very well we're going to create a 00:11:36.120 --> 00:11:43.300 function f to OK which will be applied to variable to before being stored in the table. 00:11:43.440 --> 00:11:46.020 OK so this creates that function. 00:11:46.590 --> 00:11:47.410 OK. 00:11:47.850 --> 00:11:53.570 So function f 2 is going to take one parameter. 00:11:53.960 --> 00:11:55.060 OK. 00:11:55.930 --> 00:11:56.340 OK. 00:11:56.400 --> 00:12:02.660 String and this will give us an output using a hashing algorithm. 00:12:02.670 --> 00:12:03.160 OK. 00:12:03.480 --> 00:12:10.560 So that we can reverse the process and find a if we have the outputs of the function. 00:12:10.560 --> 00:12:17.520 So the function we are going to use here is going to be harsh as we did before. 00:12:17.690 --> 00:12:21.840 OK. 00:12:27.590 --> 00:12:28.220 OK. 00:12:28.680 --> 00:12:36.210 Are we going to store the outputs inside a variable b for example. 00:12:36.210 --> 00:12:43.870 So again we're going to have a couple of promises so the first one is going to be s Ha 2 5 six. 00:12:44.000 --> 00:12:44.420 OK. 00:12:44.520 --> 00:12:45.600 As we did before. 00:12:45.930 --> 00:12:50.730 And the second barometer is variable 8. 00:12:51.620 --> 00:12:52.040 OK. 00:12:52.050 --> 00:12:56.750 And then we're going to return B. 00:12:58.350 --> 00:13:07.000 So function f 2 is going to return the hash of a using the algorithm SH 8 2 5 6. 00:13:07.020 --> 00:13:09.590 OK. 00:13:09.600 --> 00:13:17.220 So our variable if to also has vacated 2 is just going to be EF 2. 00:13:17.260 --> 00:13:19.930 Applied to the second variable. 00:13:20.040 --> 00:13:21.530 Okay. 00:13:22.260 --> 00:13:24.840 Which is also as we cater to. 00:13:24.940 --> 00:13:25.790 All right. 00:13:25.980 --> 00:13:28.950 Now let's move to the user ID. 00:13:29.520 --> 00:13:34.050 So very simply the user id OK can be retrieved from the session 00:13:36.570 --> 00:13:37.290 variable. 00:13:37.500 --> 00:13:37.800 OK 00:13:37.800 --> 00:13:47.830 . 00:13:48.240 --> 00:13:53.570 And we're looking at the elements corresponding to user ID. 00:13:54.020 --> 00:13:54.700 OK. 00:13:55.050 --> 00:13:58.560 And finally the expiration variable 00:14:05.220 --> 00:14:07.580 is going to be a date and time value. 00:14:07.740 --> 00:14:08.070 OK. 00:14:08.070 --> 00:14:10.750 Which is going to be 15 days from now. 00:14:10.890 --> 00:14:17.150 So we're going to use the Date function as we covered in the BHB chapter. 00:14:17.250 --> 00:14:20.450 So this function again is going to take a couple of Ramos's. 00:14:20.610 --> 00:14:22.990 So the first priority is going to be reformats. 00:14:23.060 --> 00:14:23.820 Okay. 00:14:24.130 --> 00:14:28.180 But we'd like to use for our date or date and time. 00:14:28.710 --> 00:14:33.660 And the second barometer is going to be the Unix timestamp. 00:14:33.720 --> 00:14:36.990 So our Unix timestamp is going to be the same as the cookie. 00:14:37.330 --> 00:14:37.720 Okay. 00:14:37.740 --> 00:14:47.860 Which is the current time plus that's amounts of seconds which is the equivalent of 15 days. 00:14:48.120 --> 00:14:56.440 And for the formants okay to be able to manipulate the data later in the table. 00:14:56.490 --> 00:14:56.890 Okay. 00:14:56.970 --> 00:14:58.230 Or using my Escurial. 00:14:58.320 --> 00:15:05.660 We're going to go for the following full months which is year Ifan month hyphen day. 00:15:05.840 --> 00:15:06.650 Okay. 00:15:06.660 --> 00:15:13.600 And that space our minutes then seconds. 00:15:13.770 --> 00:15:15.540 Okay. 00:15:16.320 --> 00:15:18.100 Now let's run our query. 00:15:18.360 --> 00:15:21.780 Okay. 00:15:24.570 --> 00:15:29.360 So to run the query we're going to create a variable results. 00:15:29.580 --> 00:15:30.150 Okay. 00:15:30.330 --> 00:15:35.550 Are we going to store the output of the function Maia's Kali on this call Square. 00:15:35.950 --> 00:15:39.090 So it's going to take a couple of promises again. 00:15:39.210 --> 00:15:44.420 The link variable and our query as well. 00:15:45.720 --> 00:15:51.680 Okay now we're going to check if the query has been run successfully. 00:15:52.110 --> 00:15:54.360 So are you going to check if 00:15:58.710 --> 00:16:00.400 opposites of results. 00:16:00.510 --> 00:16:01.350 Okay. 00:16:01.620 --> 00:16:08.550 So by the way if the query is not successful this is going to return a boolean false and the opposite 00:16:08.580 --> 00:16:09.960 of falles is going to be true. 00:16:09.960 --> 00:16:18.400 So if true then we're going to echo an error message. 00:16:19.980 --> 00:16:24.440 Otherwise we're just going to echo success. 00:16:24.600 --> 00:16:27.060 Okay. 00:16:29.010 --> 00:16:34.880 And the loggin file is going to return success. 00:16:34.920 --> 00:16:35.330 Okay. 00:16:35.400 --> 00:16:38.750 And we're going to play that's in the Ajax code. 00:16:39.030 --> 00:16:39.930 Okay. 00:16:39.930 --> 00:16:45.840 So the error message can be copied from previous code 00:16:49.030 --> 00:16:51.080 is from the 00:16:55.290 --> 00:16:56.330 end. 00:16:56.580 --> 00:17:05.120 Let's say something like there was an error storing data to remember you next time. 00:17:05.280 --> 00:17:06.350 OK. 00:17:07.290 --> 00:17:10.410 There is a dormer missing that. 00:17:10.500 --> 00:17:11.290 OK. 00:17:11.680 --> 00:17:12.270 All right. 00:17:12.270 --> 00:17:16.170 Now let's have a quick look at the structure of the Remember Me table. 00:17:16.260 --> 00:17:16.760 OK. 00:17:16.920 --> 00:17:28.080 So also the became the one as bean is going to store the variable was as big as the one which we generated 00:17:28.200 --> 00:17:34.170 using the function open as a cell run them pseudo bytes and we generated 10 bytes. 00:17:34.200 --> 00:17:34.890 OK. 00:17:35.520 --> 00:17:38.470 OK so 10 bytes is 10. 00:17:38.730 --> 00:17:41.420 Multiply by 8 beats OK. 00:17:41.520 --> 00:17:53.260 So there's 80 bits which is the equivalent of two multiply by two 80 times. 00:17:53.340 --> 00:17:54.090 OK. 00:17:54.690 --> 00:18:03.630 So if you represent this in X it is simple OK then we need to find how many times what are we're actually 00:18:03.690 --> 00:18:04.350 multiplying. 00:18:04.350 --> 00:18:05.550 16. 00:18:05.990 --> 00:18:10.760 OK so 16 is two multiplied four times. 00:18:10.800 --> 00:18:11.520 OK. 00:18:11.890 --> 00:18:19.800 So to get that number we're going to divide eighty times OK by 4. 00:18:19.800 --> 00:18:23.670 So 80 divided by four is going to give us 20. 00:18:23.910 --> 00:18:28.280 So you need to have a chore 20 for that call. 00:18:28.440 --> 00:18:29.240 OK. 00:18:29.640 --> 00:18:30.540 So that's a bet that's 00:18:35.740 --> 00:18:39.340 OK save. 00:18:39.760 --> 00:18:40.860 All right. 00:18:41.070 --> 00:18:45.140 Now let's look at if two authors vacate too. 00:18:45.150 --> 00:18:50.300 So the value of that is the output of the function. 00:18:51.570 --> 00:18:53.500 Hush. 00:18:53.560 --> 00:18:54.060 OK. 00:18:54.090 --> 00:18:57.850 Using the algorithm is 8 to 5 6. 00:18:57.930 --> 00:19:01.230 Ok which gives us 256 bits. 00:19:01.320 --> 00:19:02.270 OK. 00:19:03.210 --> 00:19:09.400 So to find the number of characters we need we need to divide that 256 bits by four. 00:19:09.470 --> 00:19:09.950 OK. 00:19:10.020 --> 00:19:12.260 Which will give us 64 and that's the right number. 00:19:12.270 --> 00:19:13.960 We have adman's. 00:19:14.490 --> 00:19:19.950 OK before we test our code this Rexy if I say something in our query I'm missing the single quotes for 00:19:19.950 --> 00:19:20.760 the values. 00:19:20.910 --> 00:19:23.460 Ok so 00:19:31.950 --> 00:19:36.280 now we're ready to test our code which we're going to do in the next video{"threads":[{"position":24753014,"start":0,"end":24753013,"connection":"closed"},{"position":48869655,"start":24753014,"end":49506025,"connection":"open"}],"url":"https://a2.udemycdn.com/2016-07-30_22-21-33-c173fa4cc8585a2bd9cef811c98d10c2/WebHD_720p.mp4?nva=20190604183200&token=04f25a944513e6a9d35d4","method":"GET","port":443,"downloadSize":49506025,"headers":{"date":"Tue, 21 May 2019 17:00:01 GMT","content-type":"binary/octet-stream","content-length":"49506025","connection":"close","etag":"\"a500a8424e0dc9abec4a3a8095273d28\"","last-modified":"Thu, 30 Aug 2018 22:23:57 GMT","server":"AmazonS3","x-amz-id-2":"AEwNFktp8dUaj35ZuzA2cBSaVPVJCh8cgCj4HsYXXU/4zfQ6HJ3bvROEz/z154yAxOBphhVx3t8=","x-amz-replication-status":"COMPLETED","x-amz-request-id":"C7E5E1BA905A78B4","x-amz-storage-class":"INTELLIGENT_TIERING","x-amz-version-id":"_T3pwKELoWaKFtypXlni2B1J3FCswViF","access-control-allow-origin":"*","age":"1201506","accept-ranges":"bytes"}}