UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.81 kB
import{copy as e}from"../../../libs/i18n/copy.mjs";import t from"../../../constants/constants.mjs";import{decrypt as n}from"../../../utils/helpers/encrypt-decrypt.mjs";import r from"../../../utils/helpers/generate-secret.mjs";import{scrypt as i}from"@noble/hashes/scrypt.js";const a=e=>e!==void 0&&e.trim()!==``,o=async(o,s)=>{let c,l;if(a(s.newPassword)&&a(s.currentPassword)===!1)return{error:{type:`basic`,message:e(`server:core.input.provide.current.password`),status:400,errors:{currentPassword:{code:`required`,message:e(`server:core.input.provide.current.password`)}}},data:void 0};if(a(s.currentPassword)&&a(s.newPassword)===!1)return{error:{type:`basic`,message:e(`server:core.input.provide.new.password`),status:400,errors:{newPassword:{code:`required`,message:e(`server:core.input.provide.new.password`)}}},data:void 0};if(!a(s.newPassword)&&!a(s.currentPassword))return{error:void 0,data:{newPassword:c,triggerPasswordReset:l,encryptSecret:void 0}};if(s.newPassword!==s.passwordConfirmation)return{error:{type:`basic`,message:e(`server:core.input.ensure.passwords.match`),status:400,errors:{passwordConfirmation:{code:`invalid`,message:e(`server:core.input.ensure.passwords.match`)}}},data:void 0};let u=n(s.encryptedSecret,s.encryptionKey);if(Buffer.from(i(s.currentPassword,u,t.scrypt)).toString(`base64`)!==s.password)return{error:{type:`basic`,message:e(`server:core.input.ensure.password.is.correct`),status:400,errors:{currentPassword:{code:`invalid`,message:e(`server:core.input.ensure.password.is.correct`)}}},data:void 0};let{secret:d,encryptSecret:f}=r(s.encryptionKey);return c=Buffer.from(i(s.newPassword,d,t.scrypt)).toString(`base64`),l=!1,{error:void 0,data:{newPassword:c,triggerPasswordReset:l,encryptSecret:f}}};export{o as default}; //# sourceMappingURL=check-update-password.mjs.map