Password hashing to db

This commit is contained in:
Jörn-Michael Miehe 2018-10-04 02:27:49 +02:00
parent 68c63563ef
commit 613dd1bb4a
3 changed files with 47 additions and 0 deletions

View file

@ -11,6 +11,8 @@
"express": "^4.16.1",
"helmet": "*",
"socket.io": "^2.1.1",
"mysql": "*",
"bcrypt": "*",
"coffeescript": "*",
"merge-stream": "*",
"gulp": "*",

View file

@ -2,6 +2,8 @@
var
http = require('http'),
socketio = require('socket.io'),
mysql = require('mysql'),
bcrypt = require('bcrypt'),
express = require('express'),
gulp = global.gulp = require('gulp'),
helmet = require('helmet');
@ -25,6 +27,18 @@ app.use(helmet());
// Static content
app.use(express.static(__dirname + '/static'));
var con = mysql.createConnection({
host: "tcgsql",
user: "fftcg",
database: "fftcg",
password: "juchie5OhH6eiQuujaoquievezoe9iXe",
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected to TCGSQL!");
});
// Server logic
io.on('connection', function (socket) {
console.log('a user connected');
@ -35,5 +49,14 @@ io.on('connection', function (socket) {
socket.on('login', function(msg){
console.log('message:', msg.uname, msg.password);
const saltRounds = 13;
bcrypt.hash(msg.password, saltRounds, function(err, hash) {
con.query('INSERT INTO `users` (nick, pwd_hash) VALUES (\'' + msg.uname + '\', \'' + hash + '\');', function (err, result) {
if (err) throw err;
console.log("Result: " + result);
});
});
});
});

22
users.sql Normal file
View file

@ -0,0 +1,22 @@
-- Adminer 4.6.3 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP DATABASE IF EXISTS `fftcg`;
CREATE DATABASE `fftcg` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `fftcg`;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`nick` varchar(100) NOT NULL,
`pwd_hash` char(64) NOT NULL,
`socket_id` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1;
-- 2018-10-04 00:24:51