From 754cfbc7b044ac1dbbb04fc9cfd7a236e69f69ca Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Thu, 15 Feb 2018 14:35:04 +0100 Subject: [PATCH] MD5 in password web access --- services/loopback/common/models/account.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/loopback/common/models/account.js b/services/loopback/common/models/account.js index 4209ca51a..d58ad5f60 100644 --- a/services/loopback/common/models/account.js +++ b/services/loopback/common/models/account.js @@ -1,7 +1,16 @@ +const md5 = require('md5'); + module.exports = function(Self) { // Validations Self.validatesUniquenessOf('name', { message: 'Ya existe un usuario con ese nombre' }); + + Self.observe('before save', (ctx, next) => { + if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password) { + ctx.data.password = md5(ctx.data.password); + } + next(); + }); };