From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
0.00 Welcome to the 3rd part of the User Registration tutorial. In this part we are going to check for existence of all that was discussed in the last part.
0.10 Let us have a quick recap of what was done in the last part.
0:14 We have striped the tags off our "fullname" and "username".
0:19 We have stripped and encrypted our "password".
0:22 Remember this sequence for the functions, so that we are not striping off our encrypted value.
0:30 Here we are going to start our registration process. I'll be checking the existence of all these.
0:38 Just before I do that I am going to set the "date". Now, this is using the date function.
0:46 Inside we have "Y" for the year "m" for the month and "d" for the date.
0:55 It's the capital "Y" for a 4-digit year. If we use a small "y", we would have a 2-digit year.
1:02 So, in my database, at the moment. I have my year first, then my month and my day and these are separated by hyphens.
1:15 You can see this when we enter our database here and say insert a value into "users".
1:22 We can see that the "date" is in a specific format, if we use this kind of function here.
1:29 When I click today, you can see here that we have got the year in a 4-digit format and our month here and our day here, separated by hyphens.
1:40 Its adjusted into that structure inside my database.
1:44 Okay, so "if submit", then we need to check for existence. I will add a comment here "check for existence".
1:55 Now, this is really easy. All we want to do is we have to say is "if" statement and a block a code after that.
2:05 The condition will be "if fullname, username, password and repeat password exist".... we have the evidence here.... we will say "if username" followed by "and", so double ampersand symbol.
2:24 Then we will say "password" and then we'll say....
2:28 Oh! I forgot the "fullname" here, so I'll add it here.
2:32 Separated these with a double ampersand sign.
2:37 The last one is "repeat password" so type that.
2:42 We are going to require all of these.
2.45 Else, we will say - echo "Please fill in" and in bold, "all fields".
2:57 We will put a paragraph break after that.
3:01 Also let me put a paragraph break before the form so that we don't need to add it to every error message we give.
3:10 So that's it. Let's just try it.
3:13 I will go back to my "register" page. We got it here. Lets click in register.
3:20 "Please fill in all fields".
3:23 Lets type a couple of fields here.
3:25 Lets choose one of our passwords. We will not repeat our password.
3:30 Register. Oh! repeat password..... repeat password.
3.45 The reason this is not working at the moment is, an "md5" value of nothing is equal to an "md5" string of text. An encrypted string of text.
4:00 So, I realise what we need to do is, take out the "md5" function here.
4:06 Make sure you remove the end brackets. I will come down here and check for all of our data.
4:14 So, let me go back and try this again.
4:17 Remember it didn't work before when we didn't chose a "repeat password".
4:23 So if I didn't chose a password or a repeat password we get our error.
4:30 If I again choose a value except the repeat password, we still get this error.
4:37 That's the problem. What we should say is - if everything exists then we can convert our password and repeat password.
4:46 So I will just say "password" is equal to "md5" of password".
4:53 This will encrypt our original variable value and store a new password code in the same variable.
5:00 We also need to say "repeat password" equals "md5" and "repeat password".
5:08 Here comment this as "encrypt password". We have encrypted our password.
5:15 Now we will go ahead and add all our data into our data base.
5:21 I am going to do this. Because we have got our data going to our registration, we are going to set a maximum limit for each data that is input.
5:38 Now we say 25 characters for our fullname, username, password and repeat password. So the maximum value is 25.
5:50 So I will say- if the string length of username is bigger or greater than 25.... or.... string length of the fullname is greater that 25
6:15 Let us look at these individually and say if the length of your username or fullname is too long.
6:24 Let me put this correctly.
6:27 If each of these values is greater than 25 or bigger than 25.
6:34 We are going to echo out these values saying "username" or...... no....
6:48 Let me say "Max limit for username or fullname are 25 characters".
6:55 Otherwise I will proceed to check my password length.
7:00 Now I have decided to do this - "check password length" because I want a specific check for this.
7:12 Let me say "if string length of my password is greater than 25.... or.... string length.....
7:30 No... um... lets get rid of this, get rid of "else".
7:36 The first check I want to do is to see if my passwords match.
7:41 Let me say "if password equals equals to repeat password" then continue the big block of code.
7:53 Otherwise echo out to the user "Your passwords do not match". Okay?
8:03 So, you can type here and we can keep checking our character length.
8:09 Now to check the character length of "username" and "fullname". So, "check char length of username and fullname".
8:18 And that is going to be what we said before, "if username is greater than 25"
8:25 Rather if the string length used in this function is greater than 25...
8.31 Or the string length of fullname is greater that 25, then we echo "Length of username or fullname is too long!".
8:42 So, just to keep it simple and then otherwise we will say "check password length".
8:57 Here I am going to specify or say "if"... now remember our passwords match...
9:04 So we only need to check this on one of the password variables.
9:09 Here I will say - if the string length of the password is greater than 25 or string length of our password is lesser than 6 characters....
9.22 ...then we will echo out an error saying "Password must be between 6 and 25 characters". This will work for sure.
9:37 We will continue this discussion in the next tutorial.
9:41 Before that let me just conclude this with an "else" statement.
9:46 So, otherwise we will say "register the user". Our code to register the user will go here.
9:55 In the next tutorial we'll test this out and will learn how to register the user and we will put our code here in that tutorial.
10:05 This is basically for checking a minimum or maximum limit on our password and this block of code here is will be our magical "register the user" piece of code.
10:17 So join me in the next part. Bye-bye. This is ____________ dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Chandrika, Kavita salve, Pravin1389