Files
klz-cables.com/.pnpm-store/v10/files/ec/e48e3eb38c676940ee4aaa460b5cdb8a70113af6e44a6e9fb1161c7852265daa2df26a5a0a18d6f0bbdb3628f29cab64a411124ea63ccf9791e97fa9f712a2
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

48 lines
1.5 KiB
Plaintext

import crypto from 'crypto';
import { ValidationError } from '../../../errors/index.js';
import { password } from '../../../fields/validations.js';
function randomBytes() {
return new Promise((resolve, reject)=>crypto.randomBytes(32, (err, saltBuffer)=>err ? reject(err) : resolve(saltBuffer)));
}
function pbkdf2Promisified(password, salt) {
return new Promise((resolve, reject)=>crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (err, hashRaw)=>err ? reject(err) : resolve(hashRaw)));
}
export const generatePasswordSaltHash = async ({ collection, password: passwordToSet, req })=>{
const validationResult = password(passwordToSet, {
name: 'password',
type: 'text',
blockData: {},
data: {},
event: 'submit',
path: [
'password'
],
preferences: {
fields: {}
},
req,
required: true,
siblingData: {}
});
if (typeof validationResult === 'string') {
throw new ValidationError({
collection: collection?.slug,
errors: [
{
message: validationResult,
path: 'password'
}
]
});
}
const saltBuffer = await randomBytes();
const salt = saltBuffer.toString('hex');
const hashRaw = await pbkdf2Promisified(passwordToSet, salt);
const hash = hashRaw.toString('hex');
return {
hash,
salt
};
};
//# sourceMappingURL=generatePasswordSaltHash.js.map