Password hashing to db
This commit is contained in:
parent
68c63563ef
commit
613dd1bb4a
3 changed files with 47 additions and 0 deletions
|
@ -11,6 +11,8 @@
|
||||||
"express": "^4.16.1",
|
"express": "^4.16.1",
|
||||||
"helmet": "*",
|
"helmet": "*",
|
||||||
"socket.io": "^2.1.1",
|
"socket.io": "^2.1.1",
|
||||||
|
"mysql": "*",
|
||||||
|
"bcrypt": "*",
|
||||||
"coffeescript": "*",
|
"coffeescript": "*",
|
||||||
"merge-stream": "*",
|
"merge-stream": "*",
|
||||||
"gulp": "*",
|
"gulp": "*",
|
||||||
|
|
23
server.js
23
server.js
|
@ -2,6 +2,8 @@
|
||||||
var
|
var
|
||||||
http = require('http'),
|
http = require('http'),
|
||||||
socketio = require('socket.io'),
|
socketio = require('socket.io'),
|
||||||
|
mysql = require('mysql'),
|
||||||
|
bcrypt = require('bcrypt'),
|
||||||
express = require('express'),
|
express = require('express'),
|
||||||
gulp = global.gulp = require('gulp'),
|
gulp = global.gulp = require('gulp'),
|
||||||
helmet = require('helmet');
|
helmet = require('helmet');
|
||||||
|
@ -25,6 +27,18 @@ app.use(helmet());
|
||||||
// Static content
|
// Static content
|
||||||
app.use(express.static(__dirname + '/static'));
|
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
|
// Server logic
|
||||||
io.on('connection', function (socket) {
|
io.on('connection', function (socket) {
|
||||||
console.log('a user connected');
|
console.log('a user connected');
|
||||||
|
@ -35,5 +49,14 @@ io.on('connection', function (socket) {
|
||||||
|
|
||||||
socket.on('login', function(msg){
|
socket.on('login', function(msg){
|
||||||
console.log('message:', msg.uname, msg.password);
|
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
22
users.sql
Normal 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
|
Reference in a new issue