Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정성훈
/
MEALKHU
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
swa07016
2020-06-08 01:12:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dfffbedbe839abecb0e051978fcd567d7767c5bc
dfffbedb
1 parent
51f6f636
bcrypt를 이용한 패스워드 암호화
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
17 deletions
package-lock.json
package.json
server.js
package-lock.json
View file @
dfffbed
This diff is collapsed. Click to expand it.
package.json
View file @
dfffbed
...
...
@@ -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"
,
...
...
server.js
View file @
dfffbed
...
...
@@ -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,23 +44,26 @@ 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
];
connection
.
query
(
sql
,
params
,
(
err
,
rows
,
fields
)
=>
{
if
(
err
){
console
.
log
(
err
);
res
.
send
({
"code"
:
400
,
"message"
:
"error"
})
}
else
{
res
.
send
({
"code"
:
200
,
"message"
:
"success"
})
}
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
);
res
.
send
({
"code"
:
400
,
"message"
:
"error"
})
}
else
{
res
.
send
({
"code"
:
200
,
"message"
:
"success"
})
}
})
})
})
app
.
listen
(
port
,
()
=>
console
.
log
(
`Listening on port
${
port
}
`
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment