Skip to content

Instantly share code, notes, and snippets.

@ZaneHannanAU
Created July 25, 2017 04:49
Show Gist options
  • Save ZaneHannanAU/e9c89a44ebc3cd4b4a58e0a8a9ad06cf to your computer and use it in GitHub Desktop.
Save ZaneHannanAU/e9c89a44ebc3cd4b4a58e0a8a9ad06cf to your computer and use it in GitHub Desktop.
A function to remove "bad" words from generated XKCD passwords.
# 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.*
{ "name": "xkcd-z-password-nobadwords",
"description": "efficient XKCD-z-password badword remover function",
"main": "xkcd-nobad-password.js" }
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