mirror of
https://github.com/strapi/strapi.git
synced 2025-09-07 07:41:08 +00:00
Don't check if it has already been hashed
This commit is contained in:
parent
aa28c2c37a
commit
ecaa98ef6e
@ -3,24 +3,10 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const { AttributeProcessor } = require('./processor');
|
||||
|
||||
/** Explanation for the isHashed RegExp
|
||||
* Starts with $2b$ => /\$2b\$
|
||||
* Then is followed by 2 digits and a $ sign. => \d{2}\$
|
||||
* Ends with 53 alphanumerics characters (plus . and /) => [./a-z-A-Z0-9]{53}/
|
||||
*/
|
||||
const bcryptHashRegExp = /\$2b\$\d{2}\$[./a-z-A-Z0-9]{53}/;
|
||||
|
||||
const transformActions = ['create', 'update'];
|
||||
|
||||
const isHashed = value => bcryptHashRegExp.test(value);
|
||||
|
||||
class PasswordProcessor extends AttributeProcessor {
|
||||
transform(value, context) {
|
||||
// Don't update the value if it has already been hashed
|
||||
if (isHashed(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
const { action } = context;
|
||||
|
||||
if (!transformActions.includes(action)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user