Browse Source

hash of passwords with md5 done

pull/2/head
idoctnef 8 years ago
parent
commit
93abe78f57
2 changed files with 8 additions and 3 deletions
  1. +6
    -2
      controllers/userController.js
  2. +2
    -1
      package.json

+ 6
- 2
controllers/userController.js

@ -2,6 +2,8 @@
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var userModel = mongoose.model('userModel'); var userModel = mongoose.model('userModel');
var md5 = require('md5');
/* */ /* */
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
var express = require("express"); var express = require("express");
@ -70,7 +72,7 @@ exports.addUser = function(req, res) {
var user = new userModel({ var user = new userModel({
username: req.body.username, username: req.body.username,
password: req.body.password,
password: md5(req.body.password),
description: req.body.description, description: req.body.description,
avatar: req.body.avatar, avatar: req.body.avatar,
mail: req.body.mail, mail: req.body.mail,
@ -88,7 +90,7 @@ exports.addUser = function(req, res) {
exports.updateUser = function(req, res) { exports.updateUser = function(req, res) {
userModel.findById(req.params.id, function(err, user) { userModel.findById(req.params.id, function(err, user) {
user.username = req.body.username; user.username = req.body.username;
user.password = req.body.password;
user.password = md5(req.body.password);
user.description = req.body.description; user.description = req.body.description;
user.avatar = req.body.avatar; user.avatar = req.body.avatar;
user.mail = req.body.mail; user.mail = req.body.mail;
@ -128,6 +130,8 @@ exports.login = function(req, res) {
res.json({ success: false, message: 'Authentication failed. User not found.' }); res.json({ success: false, message: 'Authentication failed. User not found.' });
} else if (user) { } else if (user) {
req.body.password=md5(req.body.password);
// check if password matches // check if password matches
if (user.password != req.body.password) { if (user.password != req.body.password) {
res.json({ success: false, message: 'Authentication failed. Wrong password.' }); res.json({ success: false, message: 'Authentication failed. Wrong password.' });

+ 2
- 1
package.json

@ -12,6 +12,7 @@
"jsonwebtoken": "latest", "jsonwebtoken": "latest",
"method-override": "^2.1.2", "method-override": "^2.1.2",
"mongoose": "latest", "mongoose": "latest",
"morgan": "latest"
"morgan": "latest",
"md5": "latest"
} }
} }

Loading…
Cancel
Save