Created
July 25, 2017 04:49
-
-
Save ZaneHannanAU/e9c89a44ebc3cd4b4a58e0a8a9ad06cf to your computer and use it in GitHub Desktop.
A function to remove "bad" words from generated XKCD passwords.
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
# Newline separated badwords filter using Regular expressions | |
assh.* | |
bitch.* | |
chink | |
cunt.* | |
daygo | |
dick.* | |
douche | |
fag.* | |
fatass | |
lesb.* | |
nigg.* | |
puss(y|ies) | |
retard | |
shemale | |
shit.* | |
skank.* | |
slut.* | |
wetback | |
whore.* |
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
{ "name": "xkcd-z-password-nobadwords", | |
"description": "efficient XKCD-z-password badword remover function", | |
"main": "xkcd-nobad-password.js" } |
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 fs = require('fs'); | |
const path = require('path'); | |
const xkcdPassword = require('xkcd-z-password'); | |
let badwordsRaw = fs.readFileSync(path.join(__dirname, 'badwords.txt')) | |
.replace(/^(#|\/\/).+$/gm, '') | |
.replace(/\r?\n/g, '|') | |
.replace(/^\|+|\|+$|(\|)\|+/g, '$1') | |
let badwords = new RegExp(`^(${badwordsRaw})$`, 'gi') | |
module.exports = exports = xkcdPassword.init({ | |
numWords: 4, minLength: 5, maxLength: 8, | |
filter(word) { | |
return ( | |
word.length >= minLength | |
&& word.length <= maxLength | |
&& !badwords.test(word) | |
// It's inefficient but still usable | |
) | |
} | |
}); | |
exports.badwords = badwords; | |
exports.badwordsRaw = badwordsRaw; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Packaged: