### Usage
Same as `proxy`.
+
+## pwned
+
+Checks a password against the [have i been pwned?](https://haveibeenpwned.com/) API and returns a boolean indicating if the password has been pwned or not. This is a simplified re-implementation of the [Pwned Passwords Cloudflare Worker](https://github.com/HaveIBeenPwned/PwnedPasswordsCloudflareWorker).
+
+### Usage
+
+Pass a plaintext password as the entire query string to the endpoint. For example, if your Cloudflare Worker domain is
+```
+https://x.y.workers.dev
+```
+and the password you want to check is
+```
+hunter1
+```
+then the final request URL should be
+```
+https://x.y.workers.dev?hunter1
+```
\ No newline at end of file
--- /dev/null
+async function handleRequest(request) {
+ const url = new URL(request.url);
+ const queryString = decodeURIComponent(url.search.substring(1));
+
+ // Convert password string to byte array and hash it, then convert hashed byte array to hex string
+ const inputArray = new TextEncoder().encode(queryString);
+ const digest = await crypto.subtle.digest('SHA-1', inputArray);
+ const outputArray = [...new Uint8Array(digest)]; // Need to spread typed array into a non-typed array to allow .map() to output strings
+ const hash = outputArray.map(v => v.toString(16).padStart(2, '0')).join('').toUpperCase();
+
+ // Split the hash as required by the HIBP API (k-Anonymity model)
+ const range = hash.substring(0, 5);
+ const index = hash.substring(5);
+
+ const result = fetch(`https://api.pwnedpasswords.com/range/${range}`)
+ .then(response => response.text())
+ .then(body => body.includes(index))
+ .then(bool => new Response(bool));
+
+ return result;
+}
+
+addEventListener('fetch', event => {
+ event.respondWith(handleRequest(event.request));
+})
--- /dev/null
+{
+ "name": "pwned",
+ "version": "0.1.0",
+ "description": "This is a re-implementation of the Pwned Passwords Cloudflare Worker.",
+ "private": true,
+ "main": "index.js",
+ "scripts": {
+ "login": "wrangler login",
+ "preview": "wrangler preview",
+ "build": "wrangler build",
+ "publish": "wrangler publish"
+ },
+ "author": "Ardis Lu",
+ "license": "ISC",
+ "devDependencies": {
+ "@cloudflare/wrangler": "^1.16.1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/ardislu/cloudflare-workers.git"
+ }
+}