Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option of limited special characters #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ program
.option('-s, --save', 'save password to passwords.txt')
.option('-nn, --no-numbers', 'remove numbers')
.option('-ns, --no-symbols', 'remove symbols')
//limited symbols
.option('-ls, --limited-symbols <String>', 'limited symbols')
.parse()

const {length, save, numbers, symbols} = program.opts()
const {length, save, numbers, symbols, limitedSymbols} = program.opts()

//console.log(numbers, symbols)

//get generated password
const generatedPassword = createPassword(length, numbers, symbols)
const generatedPassword = createPassword(length, numbers, symbols, limitedSymbols)

//Save to file
if(save) {
Expand Down
349 changes: 348 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions utils/createPassword.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
const alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
const numbers = '0123456789'
const symbols = '!@#$%^&*_-+='

const createPassword = (length = 8, hasNumbers = true, hasSymbols = true) => {
const createPassword = (length = 8, hasNumbers = true, hasSymbols = true, limitedSymbols = symbols) => {
let chars = alpha
if (limitedSymbols.length == 0) {
hasSymbols = false;
}
hasNumbers ? (chars += numbers) : ''
hasSymbols ? (chars += symbols) : ''
hasSymbols ? (chars += limitedSymbols) : ''
return generatePassword(length, chars)
}
const generatePassword = (length, chars) => {
let password = ''
for(let i=0; i<length; i++){
for (let i = 0; i < length; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length))
}

Expand Down