PHP-and-MySQL/C4/User-Password-Change-Part-1/English-timed

From Script | Spoken-Tutorial
Revision as of 16:36, 25 October 2013 by Gyan (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
0:00 Welcome. In this tutorial, we will talk about how a user can change their password.
0:08 We will learn how to give the user the option to change their password if they want to.
0:13- This shouldn’t take too long. It will be covered in 3 parts.
0:18 We’ll give the user a form and ask the user to type their old password and their new password twice.
0:27 We will check their old password, the one that’s in the database.
0:31 Remember, they’re encrypted.
0:33 Then we will compare the two new passwords to see if they match, to see if they’ve made any mistake.
0:39 Next we will update the database using the new sql codes.
0:44 So first of all I will start my "session" on my "member" page. As you can see we’ve got our "session_start" here.
0:53 I’ll just copy and paste that to the top of my page. So, we’ve started our session.
0:59 We need to use a variable called "user" which will be equal to the session that we’ve set over here.
1:09 First, we need to check that the users have logged in - this is the code I was talking about - before we start to change their password or let them change their password.
1:19 I’ll set this "user" variable as our "session" name which is here.
1:24 Okay, now we will say “ if the user exists”, we’ll let them change their password otherwise we kill the page and say “You must be logged in to change your password".
1:41 This is the block for “User is logged in”. So, assuming the user has logged in, after we’ve checked for the existence of the login , we need to give them a form to fill up.
1:49 I'll echo out our code here which will be our form. It’s a self- submitting form so it’ll to go back to "change password dot php" and end the form here.
2:14 So that's the page we are already on and so I’ll use a check to verify all the details.
2:21 The method of the form is POST because we don’t want to let any password information into the URL.
2:30 Next we’ll create a few input boxes. First “Old password:” which won't be a password type, so the entry won't be hidden. So input type will be "text" and name will "password".
2:48 I’ll put a paragraph break. Next is "New password:" and I will create an input type as "password" so that it is hidden from everyone. The name will be “new password”.
3:02 I'll put a line break here. Now copy paste this sentence and make a few changes. The label here will be “Repeat new password” and the name will be "repeat new password" followed by a paragraph break.
3:23 Lastly we need a “submit" button. The name will be "submit" so we can check if that’s being pressed and the value will be "Change password".
3:33 Okay, so let’s go to our page. I’ll stick a link in the members’ page, in order to help us change our password.
3:40 For now, I’ll just login using the details. My password at the moment is “abc and my username is “Alex”.
3:48 Click on login. It says "Welcome Alex". Here is the member page. The session has been set. If we need to log out, we can log out. But we need another option to change our password.
4:01 So we go back to our "member dot php" page and I’ll create another link.
4:08 And that will be “Change password”.
4:11 And this will link to “change password dot php".
4:14 So if we refresh this we’ll get another option. Click here and we get our form that we had created earlier. I'll type my old password here and my new passwords in here.
4:26 Click "Change password" but nothing happens. So we want to check whether this has been submitted or not. Delete this extra line here.
4:38 What we need to do is create an If statement to say “if POST submit” which just means "has the user pressed this submit button?". The name is submit, therefore we’ve got submit written here.
4:52 And if the user has submitted then we start changing our password here.
4:59 Otherwise, if the user hasn’t submitted we’re going to echo out this code here.
5:05 If the user hasn’t already submitted, then they’ll have to present with the form here, in order to submit the form.
5:12 Let’s go ahead and test this. What we’ll do here is echo out “test” to see if this works.
5:18 Lets go back and fill in. Actually we don’t need to fill anything. We will just click the submit button. And we get an echo of “test” to show that our form has been submitted successfully.
5:34 Ok so we need to start changing the password. Delete this and here we will say “check fields”.
5:40 We’ve got a few variables that we need to set - our old password which will be equal to POST variable name “old password”. We have given that name down here in our form.
5:55 And I’ll just replicate these for each value that we are submitting.
6:00 Next one is “new password” and then we have “repeat new password”. We’ll just change these.
6:10 To make sure these are working, and I do recommend you do this all the time, echo out “old password”, “new password” and ”repeat new password”.
6:25 It check for the form existence, whether the form has been submitted, and then we get our variables and our post variables into the variable name.
6:38 I’ll echo out what we’ve typed in the box just to see if everything is working.
6:40 So my old password is “abc” and my old password is “123”. Click "Change password" and we get abc, 123 and 123.
6:52 So that form information has been submitted. There are no spelling mistakes. I can be confident that I can get my user to set up a new password.
7:00 I’m going to stop the tutorial now. In the next part I'll teach how to check the old password against the new password in the database, how to check if the new password and the repeated password match and then to change the user’s password.
7:24 Thanks for watching. This is Joushwa Mathew dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Gyan, PoojaMoolya, Pratik kamble, Priyacst, Sandhya.np14