How To Store User Credentials In a Database

Published: 20 June 2022
on channel: CS Student Strategies
1,700
13

Storing user credentials into a database is not difficult to do. Storing user credentials into a database securely is an entirely different matter. Tre shows how you can store user credentials into a MySQL database. This is not a demo on how to store credentials in production. It is a demo to show newer developers one possible way to store user credentials. If you are familiar with this topic please shower the comment section below with your expertise.

SQL SCRIPT
-- Create and Use Database
DROP DATABASE IF EXISTS auth;
CREATE DATABASE auth;
USE auth;

-- Create Table user
DROP TABLE IF EXISTS user;
CREATE TABLE user (id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
first_name VARCHAR(255),
last_name VARCHAR(255));

-- Create Table user_auth
DROP TABLE IF EXISTS user_auth;
CREATE TABLE user_auth (username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
active TINYINT(1) DEFAULT 1,
FOREIGN KEY (username) REFERENCES user(username) ON DELETE CASCADE);

-- Create User auth_user
DROP USER IF EXISTS auth_user;
CREATE USER IF NOT EXISTS 'auth_user'@'localhost' IDENTIFIED BY 'p@$sw0rd';

-- Grant All Privileges On user_auth Database to New User
-- You should only grant necessary privileges to this user but I got lazy
GRANT ALL ON `auth`.* TO 'auth_user'@'localhost';

-- Flush Privileges
FLUSH PRIVILEGES;

Github
https://github.com/fclassvisions/cred...

Package Documentation
Express Docs
https://www.npmjs.com/package/express

MySQL 2 Docs
https://www.npmjs.com/package/mysql2

Argon 2 Docs
https://www.npmjs.com/package/argon2

DotEnv Docs
https://www.npmjs.com/package/dotenv

Cors Docs
https://www.npmjs.com/package/cors

Best Algorithm For User Creds Storage
https://infosecscout.com/best-algorit...


Watch video How To Store User Credentials In a Database online without registration, duration hours minute second in high quality. This video was added by user CS Student Strategies 20 June 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,700 once and liked it 13 people.