swa07016

bcrypt를 이용한 패스워드 암호화

This diff is collapsed. Click to expand it.
......@@ -15,6 +15,7 @@
"author": "SeongHoon",
"license": "ISC",
"dependencies": {
"bcrypt": "^4.0.1",
"body-parser": "^1.19.0",
"concurrently": "^5.2.0",
"express": "^4.17.1",
......
......@@ -2,7 +2,10 @@ const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const mysql = require('mysql');
var iconv = require('iconv-lite');
const iconv = require('iconv-lite');
const bcrypt = require('bcrypt');
const saltRounds = 10;
const app = express();
const port = process.env.PORT || 5000;
......@@ -41,7 +44,10 @@ app.get('/api/datas', (req, res) => {
// signup
app.post('/api/signup', (req, res) => {
let sql = 'INSERT INTO USER (name, pw) VALUES(?, ?)';
const params = [req.body.username, req.body.password];
let plainPassword = req.body.password;
bcrypt.hash(plainPassword, saltRounds, function(err, hash) {
const params = [req.body.username, hash];
connection.query(sql, params, (err, rows, fields) => {
if(err){
console.log(err);
......@@ -57,7 +63,7 @@ app.post('/api/signup', (req, res) => {
})
}
})
})
})
app.listen(port, () => console.log(`Listening on port ${port}`));
\ No newline at end of file
......