{"record":{"id":"5e4f3ba8073aaa47","repo":"mozilla/pdf.js","slug":"incorrect-password","errorCode":null,"errorMessage":"Incorrect Password","messagePattern":"Incorrect Password","errorType":"exception","errorClass":"PasswordException","httpStatus":null,"severity":"error","filePath":"src/core/crypto.js","lineNumber":1241,"sourceCode":"        passwordBytes,\n        ownerPassword,\n        revision,\n        keyLength\n      );\n      encryptionKey = this.#prepareKeyData(\n        fileIdBytes,\n        decodedPassword,\n        ownerPassword,\n        userPassword,\n        flags,\n        revision,\n        keyLength,\n        encryptMetadata\n      );\n    }\n\n    if (!encryptionKey) {\n      throw new PasswordException(\n        \"Incorrect Password\",\n        PasswordResponses.INCORRECT_PASSWORD\n      );\n    }\n\n    if (algorithm === 4 && encryptionKey.length < 16) {\n      // Extend key to 16 byte minimum (undocumented),\n      // fixes issue19484_1.pdf and issue19484_2.pdf.\n      this.encryptionKey = new Uint8Array(16);\n      this.encryptionKey.set(encryptionKey);\n    } else {\n      this.encryptionKey = encryptionKey;\n    }\n  }\n\n  /**\n   * Set password.\n   *","sourceCodeStart":1223,"sourceCodeEnd":1259,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/crypto.js#L1223-L1259","documentation":"PasswordException with INCORRECT_PASSWORD code, thrown after both user-password and owner-password key-derivation paths failed to produce an encryption key. The supplied password does not match either the user or owner password.","triggerScenarios":"Passing a wrong password to getDocument for a Standard-encrypted PDF; a typo; a PDF whose password was changed after caching.","commonSituations":"User mistypes the password; stale cached password; copy/paste error with trailing whitespace (note: SASLprep only applies at R=6).","solutions":["Re-prompt the user for the password and call loadingTask with the new value (destroy + recreate, or pdfDocument.updatePassword).","Trim whitespace only if you are sure the producer did not include it (R<6 passwords are byte-exact, so do not over-normalize).","Check err.code === PasswordResponses.INCORRECT_PASSWORD (value 2) and show a 'wrong password' UI."],"exampleFix":"// before\nconst doc = await getDocument({ url, password: userInput }).promise;\n\n// after\ntry {\n  const doc = await getDocument({ url, password: userInput }).promise;\n} catch (e) {\n  if (e.name === 'PasswordException' && e.code === 2) {\n    showWrongPasswordError();\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await getDocument({ url, password: userInput }).promise;\n} catch (e) {\n  if (e.name === 'PasswordException' && e.code === PasswordResponses.INCORRECT_PASSWORD) {\n    showWrongPasswordError();\n    return null;\n  }\n  throw e;\n}","preventionTips":["Distinguish INCORRECT_PASSWORD (code 2) from NEED_PASSWORD (code 1) in your UI.","Do not over-normalize passwords (R<6 are byte-exact; trim only whitespace you control).","Offer a reset/recovery flow after N failed attempts."],"tags":["encryption","pdf-security","password","authentication"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}