Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정승호
/
Hexa_for_you_renewal
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
정승호
2020-05-22 21:21:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f549a28a363a63c85758882dbe713a5b24bb11cb
f549a28a
1 parent
e82997b0
비밀번호 암호화 작업
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
models/Users.js
package-lock.json
package.json
models/Users.js
View file @
f549a28
const
mongoose
=
require
(
'mongoose'
);
const
bcrypt
=
require
(
'bcrypt'
);
const
saltRounds
=
10
;
const
userSchema
=
mongoose
.
Schema
({
name
:
{
type
:
String
,
...
...
@@ -31,6 +33,27 @@ const userSchema = mongoose.Schema({
})
// password 암호화
userSchema
.
pre
(
'save'
,
function
(
next
){
var
user
=
this
;
if
(
user
.
isModified
(
'password'
)){
bcrypt
.
genSalt
(
saltRounds
,
function
(
err
,
salt
){
if
(
err
)
return
next
(
err
)
bcrypt
.
hash
(
user
.
password
,
salt
,
function
(
err
,
hash
){
if
(
err
)
return
next
(
err
)
user
.
password
=
hash
//hash 값으로 변경해서 저장
next
()
})
})
}
})
const
User
=
mongoose
.
model
(
'Users'
,
userSchema
)
...
...
package-lock.json
View file @
f549a28
This diff is collapsed. Click to expand it.
package.json
View file @
f549a28
...
...
@@ -15,6 +15,7 @@
"author"
:
"seungho"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"bcrypt"
:
"^4.0.1"
,
"body-parser"
:
"^1.19.0"
,
"express"
:
"^4.17.1"
,
"mongoose"
:
"^5.9.15"
...
...
Please
register
or
login
to post a comment