{"version":3,"file":"password.mjs","names":[],"sources":["../../src/utils/password.ts"],"sourcesContent":["import type { GenericEndpointContext } from \"@better-auth/core\";\nimport { APIError, BASE_ERROR_CODES } from \"@better-auth/core/error\";\n\nexport async function validatePassword(\n\tctx: GenericEndpointContext,\n\tdata: {\n\t\tpassword: string;\n\t\tuserId: string;\n\t},\n) {\n\tconst accounts = await ctx.context.internalAdapter.findAccounts(data.userId);\n\tconst credentialAccount = accounts?.find(\n\t\t(account) => account.providerId === \"credential\",\n\t);\n\tconst currentPassword = credentialAccount?.password;\n\tif (!credentialAccount || !currentPassword) {\n\t\treturn false;\n\t}\n\tconst compare = await ctx.context.password.verify({\n\t\thash: currentPassword,\n\t\tpassword: data.password,\n\t});\n\treturn compare;\n}\n\nexport async function checkPassword(userId: string, c: GenericEndpointContext) {\n\tconst accounts = await c.context.internalAdapter.findAccounts(userId);\n\tconst credentialAccount = accounts?.find(\n\t\t(account) => account.providerId === \"credential\",\n\t);\n\tconst currentPassword = credentialAccount?.password;\n\tif (!credentialAccount || !currentPassword || !c.body.password) {\n\t\tthrow APIError.from(\n\t\t\t\"BAD_REQUEST\",\n\t\t\tBASE_ERROR_CODES.CREDENTIAL_ACCOUNT_NOT_FOUND,\n\t\t);\n\t}\n\tconst compare = await c.context.password.verify({\n\t\thash: currentPassword,\n\t\tpassword: c.body.password,\n\t});\n\tif (!compare) {\n\t\tthrow APIError.from(\"BAD_REQUEST\", BASE_ERROR_CODES.INVALID_PASSWORD);\n\t}\n\treturn true;\n}\n"],"mappings":";;;AAGA,eAAsB,iBACrB,KACA,MAIC;CAED,MAAM,qBADW,MAAM,IAAI,QAAQ,gBAAgB,aAAa,KAAK,OAAO,GACxC,MAClC,YAAY,QAAQ,eAAe,aACpC;CACD,MAAM,kBAAkB,mBAAmB;AAC3C,KAAI,CAAC,qBAAqB,CAAC,gBAC1B,QAAO;AAMR,QAJgB,MAAM,IAAI,QAAQ,SAAS,OAAO;EACjD,MAAM;EACN,UAAU,KAAK;EACf,CAAC;;AAIH,eAAsB,cAAc,QAAgB,GAA2B;CAE9E,MAAM,qBADW,MAAM,EAAE,QAAQ,gBAAgB,aAAa,OAAO,GACjC,MAClC,YAAY,QAAQ,eAAe,aACpC;CACD,MAAM,kBAAkB,mBAAmB;AAC3C,KAAI,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,EAAE,KAAK,SACrD,OAAM,SAAS,KACd,eACA,iBAAiB,6BACjB;AAMF,KAAI,CAJY,MAAM,EAAE,QAAQ,SAAS,OAAO;EAC/C,MAAM;EACN,UAAU,EAAE,KAAK;EACjB,CAAC,CAED,OAAM,SAAS,KAAK,eAAe,iBAAiB,iBAAiB;AAEtE,QAAO"}