sails.js - How to update a hashed password with validation in Waterline? -


Waterline documents give an example of using beforeCreate to hash a password Works great unless you verify the password field and you try to update the record. Here's my snapped example:

  Type: {hasUpperCase: function} {return value.search (/ [A-Z] /)! = -1; }, HasLowerCase: function (value) {return value.search (/ [a-z] /)! = -1; }, Hanmar: function (value) {return value.search (/ [0- 9] /)! = -1; }}, Attributes: {password: {type: 'string', minimalamper: 8, above case: true, halver case: true, hanumber: true}, salt: {type: 'string'}, //. .} First create: function (value, next) {// Encrypt password and record salt. Psalty.createHash (values.password). Then (function (psalt) {values.password = psalt.hash; values.salt = psalt.salt; Next ();}) .done (null, next); },  

When I come to update the record, I get a verification error like something:

  {"password": [ { "rule": "hasUpperCase", "message": "\" hasUpperCase \ "validation rule failed to input: 'b7d58848e4eb40ec78e756d1302ef7aeb628841a40273d2465713d2231faab396669ec7bdab91c75eaf999064cfc9c3110b1211f24fbab626619730dcadfaee069b58cb4b64e6b57d1ba7c73c22d683eb783f04439c5b0d198b56d52c219c4eab35bd7b0d56696242f4be0ac70082d6dafc65d6d2f578b22ad292582fb973f'"}]}  

so here issues There are a couple of

The first is that when the record is saved to update any other field (assuming it is a user table and they are changing their profile information), the current hashes should be retained.

The second issue when and the current user wants to update their password in the current password, we should be able to rehearse the password.

To deal with any type of situation, with the use of seal or waterline standalone, any good model strategies come with the circumstances? My impression is that I have to transfer verification to one of the event handlers.

Thanks in advance.

Check this file:

< / P>

You will enter salt with password ...


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -