Homework: Setup for next class
Scavenger Hunt - Preparation for Stage 4
Create another controller in controllers/users.js
using expres.Router
.
Add support for creating a new user
Add a
users
table with name, email and password_hash fields to your databaseBuild an
/api/users
controller (controlers/users.js
)Handle POST requests to
/api/users
by adding a new user to the database with the given name and email
Handle invalid input
Return a 400 (Bad Request) status and message for these situations:
The name, email or password is missing
The email address is already used by an existing user
The password is not long enough (extension to add more checks)
Hash passwords with bcrypt
bcrypt
When creating a new user, store a hash of the users's new password in the database too.
You'll need to install bcrypt
with npm install bcrypt
.
Here's how to use bcrypt
to hash a password:
Extensions
Add more checks to the password - does it contain letters, numbers and symbols?
Support sending two passwords and check if they match
Last updated
Was this helpful?