-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·46 lines (37 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
//vorige lijn wordt shebang genoemd of bang-line
// console.log("Hello, Node.JS!");
const validator = require("email-validator"); //validates the email adress
const axios = require("axios"); //voor het uitvoeren van HTTP requests
const chalk = require('chalk'); //om met kleurtjes te werken in de terminal
const problem = chalk.red.bold;
const ok = chalk.black.bgGreenBright;
// validator.validate("ankepeeraer@hotmail.com"); // true
// console.log(process.argv)
// const email = `tjilpie@hotmail.com` // vb van een gepwned mailadres
const email = process.argv[2] // hiermee haal je de argumenten uit de command line
// console.log(email)
const mailVal = validator.validate(email) //returns true or false
if(mailVal) {
// console.log(`dit is een geldig emailadres`)
const encodedEmail = encodeURIComponent(email) //
// console.log(encodedEmail)
// GET https://haveibeenpwned.com/api/v2/breachedaccount/{account}
// voorbeeld van axios:
// axios.get('/user', {
// params: {
// ID: 12345
// }
// })
axios.get(`https://haveibeenpwned.com/api/v2/breachedaccount/${encodedEmail}`, {
"headers" : {"User-Agent" : "Node CLI Tool"} // werkt niet zonder user-agent
})
.then(function (response) {
// console.log(response.data); // geeft de data weer als je gepwned bent
console.log(problem(`OOPS, you've been pwned`))
})
.catch(function (error) {
console.log(ok(`EVERYTHING OK, you've not been pwned`)); // als er niks mis is met mailadres, mislukt de request
});
}
else {console.log(problem(`This is not a valid email adress.`))}