-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7f509c7
Showing
4 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env node | ||
|
||
const chalk = require('chalk'); | ||
|
||
const rl = require('readline'); | ||
|
||
const randoms = require('@justhxnry/randoms'); | ||
|
||
// usage function to represent help guide | ||
const usage = function() { | ||
const usageText = ` | ||
Password Generator in Command Line Interface is fast, secure and customizable. | ||
usage: | ||
pwgen | ||
`; | ||
|
||
console.log(usageText); | ||
}; | ||
|
||
// log errors with red color | ||
function errorLog(error) { | ||
const eLog = chalk.red(error); | ||
console.log(eLog); | ||
}; | ||
|
||
// log successfull request with white color | ||
function successLog(data) { | ||
const sLog = chalk.whiteBright(data); | ||
console.log(sLog); | ||
}; | ||
|
||
// prompts | ||
function prompt(question) { | ||
const r = rl.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
terminal: false | ||
}); | ||
return new Promise((resolve, reject) => { | ||
try { | ||
r.question(question, answer => { | ||
r.close(); | ||
resolve(answer); | ||
}); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}; | ||
|
||
function main() { | ||
let q = chalk.blue(`Custom password string: `); | ||
prompt(q).then(string => { | ||
if (!string) string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
|
||
q = chalk.blue(`Enter password length: `); | ||
prompt(q).then(dlength => { | ||
|
||
if (!dlength) { | ||
errorLog(`Password Length is required parameter, recieved null`); | ||
return usage(); | ||
}; | ||
|
||
try { | ||
length = Number(dlength); | ||
|
||
if (isNaN(length)) { | ||
errorLog(`Password Length must be a number, recieved "${dlength}"`); | ||
return usage(); | ||
}; | ||
|
||
var password = randoms.random(string, length); | ||
|
||
var response = `Your generated password: \n\n ${password}\n`; | ||
|
||
successLog(response); | ||
} catch (e) { | ||
errorLog(`Password Length must be a number, recieved "${length}"`); | ||
return usage(); | ||
} | ||
}); | ||
}) | ||
}; | ||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "pwgen-cli", | ||
"version": "1.0.0", | ||
"description": "Program to generate random password", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/JustHxnry/pwgen-cli.git" | ||
}, | ||
"keywords": [ | ||
"passwordgenerator", | ||
"generator", | ||
"cli" | ||
], | ||
"author": "JustHxnry", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/JustHxnry/pwgen-cli/issues" | ||
}, | ||
"homepage": "https://github.com/JustHxnry/pwgen-cli#readme", | ||
"dependencies": { | ||
"@justhxnry/randoms": "^1.0.1", | ||
"chalk": "^4.1.2", | ||
"readline": "^1.3.0" | ||
} | ||
} |