Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
11ac71eb
Commit
11ac71eb
authored
Apr 28, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Password Encryption with Bcrypt
parent
3b725380
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
...emedicine-Chat-App/backend/controllers/userControllers.js
+2
-2
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
+17
-0
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
...021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
+4
-2
No files found.
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
View file @
11ac71eb
...
@@ -49,7 +49,7 @@ const authUser = asyncHandler(async (req, res) => {
...
@@ -49,7 +49,7 @@ const authUser = asyncHandler(async (req, res) => {
const
user
=
await
User
.
findOne
({
email
});
const
user
=
await
User
.
findOne
({
email
});
//If user is already exist check it with DB data such as password
//If user is already exist check it with DB data such as password
if
(
user
)
{
if
(
user
&&
(
await
user
.
matchPassword
(
password
))
)
{
res
.
json
({
res
.
json
({
_id
:
user
.
_id
,
_id
:
user
.
_id
,
name
:
user
.
name
,
name
:
user
.
name
,
...
@@ -63,4 +63,4 @@ const authUser = asyncHandler(async (req, res) => {
...
@@ -63,4 +63,4 @@ const authUser = asyncHandler(async (req, res) => {
}
}
});
});
module
.
exports
=
{
registerUser
};
module
.
exports
=
{
registerUser
,
authUser
};
\ No newline at end of file
\ No newline at end of file
IT18021080/Telemedicine-Chat-App/backend/models/userModel.js
View file @
11ac71eb
const
mongoose
=
require
(
"
mongoose
"
);
const
mongoose
=
require
(
"
mongoose
"
);
const
bcrypt
=
require
(
"
bcryptjs
"
);
const
userSchema
=
mongoose
.
Schema
({
const
userSchema
=
mongoose
.
Schema
({
name
:
{
type
:
String
,
required
:
true
},
name
:
{
type
:
String
,
required
:
true
},
...
@@ -14,6 +15,22 @@ const userSchema = mongoose.Schema({
...
@@ -14,6 +15,22 @@ const userSchema = mongoose.Schema({
{
timestamps
:
true
}
{
timestamps
:
true
}
);
);
userSchema
.
methods
.
matchPassword
=
async
function
(
enteredPassword
)
{
//Verify Password
return
await
bcrypt
.
compare
(
enteredPassword
,
this
.
password
);
};
//I add the .pre becouse before goint to database saving
userSchema
.
pre
(
"
save
"
,
async
function
(
next
)
{
if
(
!
this
.
isModified
)
{
next
();
}
const
salt
=
await
bcrypt
.
genSalt
(
10
);
// generate strongest new salt
this
.
password
=
await
bcrypt
.
hash
(
this
.
password
,
salt
);
//add Hash and bcrypt
});
const
User
=
mongoose
.
model
(
"
User
"
,
userSchema
);
const
User
=
mongoose
.
model
(
"
User
"
,
userSchema
);
module
.
exports
=
User
;
module
.
exports
=
User
;
\ No newline at end of file
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
View file @
11ac71eb
const
express
=
require
(
"
express
"
);
const
express
=
require
(
"
express
"
);
const
{
registerUser
}
=
require
(
"
../controllers/userControllers
"
);
const
{
registerUser
,
authUser
}
=
require
(
"
../controllers/userControllers
"
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
post
(
registerUser
);
router
.
route
(
"
/
"
).
post
(
registerUser
);
router
.
post
(
"
/login
"
,
authUser
);
router
.
post
(
"
/login
"
,
authUser
);
module
.
exports
=
router
;
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment