1. Installing Third-party package bcrypt
Storing the passwords in plain text within a database is not a good idea since they can be misused, So Passwords should be encrypted
bcrypt
package provides functions to perform operations like encryption, comparison, etc- bcrypt.hash() uses various processes and encrypts the given password and makes it unpredictable
- bcrypt.compare() function compares the password entered by the user and hash against each other
Installation Command
2. Goodreads APIs for Specified Users
We need to maintain the list of users in a table and provide access only to that specified users
User needs to be registered and then log in to access the books
- Register User API
- Login User API
2.1 Register User API
Here we check whether the user is a new user or an existing user. Returns "User Already exists" for existing user else for a new user we store encrypted password in the DB
JAVASCRIPT
2.2 Login User API
Here we check whether the user exists in DB or not. Returns "Invalid User" if the user doesn't exist else we compare the given password with the DB user password
JAVASCRIPT
Status Codes
Status Codes | Status Text ID |
---|---|
200 | OK |
204 | No Response |
301 | Moved Permanently |
400 | Bad Request |
403 | Forbidden |
401 | Unauthorized |