Showing
3 changed files
with
10 additions
and
3 deletions
This diff is collapsed. Click to expand it.
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | "author": "SeongHoon", | 15 | "author": "SeongHoon", |
16 | "license": "ISC", | 16 | "license": "ISC", |
17 | "dependencies": { | 17 | "dependencies": { |
18 | + "bcrypt": "^4.0.1", | ||
18 | "body-parser": "^1.19.0", | 19 | "body-parser": "^1.19.0", |
19 | "concurrently": "^5.2.0", | 20 | "concurrently": "^5.2.0", |
20 | "express": "^4.17.1", | 21 | "express": "^4.17.1", | ... | ... |
... | @@ -2,7 +2,10 @@ const express = require('express'); | ... | @@ -2,7 +2,10 @@ const express = require('express'); |
2 | const bodyParser = require('body-parser'); | 2 | const bodyParser = require('body-parser'); |
3 | const fs = require('fs'); | 3 | const fs = require('fs'); |
4 | const mysql = require('mysql'); | 4 | const mysql = require('mysql'); |
5 | -var iconv = require('iconv-lite'); | 5 | +const iconv = require('iconv-lite'); |
6 | + | ||
7 | +const bcrypt = require('bcrypt'); | ||
8 | +const saltRounds = 10; | ||
6 | 9 | ||
7 | const app = express(); | 10 | const app = express(); |
8 | const port = process.env.PORT || 5000; | 11 | const port = process.env.PORT || 5000; |
... | @@ -41,7 +44,10 @@ app.get('/api/datas', (req, res) => { | ... | @@ -41,7 +44,10 @@ app.get('/api/datas', (req, res) => { |
41 | // signup | 44 | // signup |
42 | app.post('/api/signup', (req, res) => { | 45 | app.post('/api/signup', (req, res) => { |
43 | let sql = 'INSERT INTO USER (name, pw) VALUES(?, ?)'; | 46 | let sql = 'INSERT INTO USER (name, pw) VALUES(?, ?)'; |
44 | - const params = [req.body.username, req.body.password]; | 47 | + let plainPassword = req.body.password; |
48 | + bcrypt.hash(plainPassword, saltRounds, function(err, hash) { | ||
49 | + | ||
50 | + const params = [req.body.username, hash]; | ||
45 | connection.query(sql, params, (err, rows, fields) => { | 51 | connection.query(sql, params, (err, rows, fields) => { |
46 | if(err){ | 52 | if(err){ |
47 | console.log(err); | 53 | console.log(err); |
... | @@ -57,7 +63,7 @@ app.post('/api/signup', (req, res) => { | ... | @@ -57,7 +63,7 @@ app.post('/api/signup', (req, res) => { |
57 | }) | 63 | }) |
58 | } | 64 | } |
59 | }) | 65 | }) |
60 | - | 66 | + }) |
61 | }) | 67 | }) |
62 | 68 | ||
63 | app.listen(port, () => console.log(`Listening on port ${port}`)); | 69 | app.listen(port, () => console.log(`Listening on port ${port}`)); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment