diff --git a/package.json b/package.json index efa8c7c..90a9f0b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "express": "^4.16.1", "helmet": "*", "socket.io": "^2.1.1", + "mysql": "*", + "bcrypt": "*", "coffeescript": "*", "merge-stream": "*", "gulp": "*", diff --git a/server.js b/server.js index 9ab7d46..ca283a4 100644 --- a/server.js +++ b/server.js @@ -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); + }); + }); + }); }); diff --git a/users.sql b/users.sql new file mode 100644 index 0000000..46e0328 --- /dev/null +++ b/users.sql @@ -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