Building a Command-Line Chat App with Node.js and Socket.IO — Part 5
The other parts of this project are as follows:
Goals
In this final part, we aim to implement two functionalities as follows:
- Configure an authentication mechanism with passwords
- Secure communication between clients and servers
Let’s get started
Password-Based Authentication
A user credential is a user name and password that is bound to a particular user. In order to connect to the chat server, clients must provide their user credentials by sending the join event as the following specification:
On the server-side, we’ll design a simple schema that has only one table named accounts in which we define two columns, namely username and password as follows:
<Image>
We also use the SQLite database for handling data. However, passwords should never be stored clearly in the database. Hence, we must use a hash algorithm, for example, bcrypt in our project.
For more information about bcrypt, see https://en.wikipedia.org/wiki/Bcrypt
Setting up
Install bcrypt for our project using npm as follows:
% npm install bcrypt
Hashing passwords
to be continued
Comparing passwords
to be continued
Secure communication
to be continued