Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
This video introduces the challenge that you'll be working to complete.
Courses
Introduction to Application Security
PHP User Authentication: Securing Passwords
Resources
password_hash — Creates a new password hash using a strong one-way hashing algorithm.
password_verify — Verifies that the given hash matches the given password.
For Step 5 bonus, you could also setup the password hash to be part of the saveUser function. Either way, you need to make sure you're passing the correct information and actually hashing the password before saving it to the database.
-
0:00
[MUSIC]
-
0:03
Hey everyone, Alena here.
-
0:06
Practice is vital to becoming a proficient developer.
-
0:10
It solidifies what you've learned, causing it to stick in your memory.
-
0:14
With deliberate practice it becomes quicker and
-
0:18
easier to solve the challenges you'll face every day.
-
0:22
This session covers hashing passwords with bcrypt.
-
0:26
This practice session is intended to follow the Introduction
-
0:30
to Application Security course.
-
0:33
If you haven't taken that course already, make sure you jump over and
-
0:37
review that course.
-
0:38
There's a link in the Teacher's notes attached to this video,
-
0:42
as well as additional resources.
-
0:44
Step one, compare the string password with the password from the database.
-
0:51
I've included a database, the connection, and even grabbed the password for you.
-
0:56
All you need to do is compare the variable,
-
0:58
$dbPassword, with the string, password.
-
1:02
Take note that these should not match.
-
1:06
Step two, hash the string password with the bcrypt algorithm.
-
1:13
PHP includes built-in functionality for you to work with hashed passwords.
-
1:18
I've included links to the documentation for the functions you'll be using.
-
1:23
Step three, compare the hashed password with the password from the database.
-
1:29
Take note again that these again should not pass,
-
1:34
even though they are both the same password and they have both been hashed.
-
1:39
Step four, use the built-in function to verify the string
-
1:43
password matches the password from the database.
-
1:48
Step five, this is a bonus.
-
1:51
Use the saveUser function that I've included and
-
1:55
add a new user to the database.
-
1:57
Remember to always store the hashed password.
-
2:02
It's okay to make multiple attempts before coming to a solution.
-
2:06
That struggle to remember what you've learned and
-
2:08
apply it to the situation is what causes the knowledge to take root.
-
2:13
If you do get stuck,
-
2:14
I've included additional resources in the notes associated with this video.
-
2:19
Go ahead and give it a try, and I'll show you my solution in the next video.
You need to sign up for Treehouse in order to download course files.
Sign up