Files
cyphernode/cyphernodeconf_docker/lib/htpasswd.js
2019-06-03 17:19:55 -04:00

24 lines
478 B
JavaScript

const exec = require('child_process').exec;
module.exports = async ( password ) => {
if( !password ) {
return null;
}
password = password.replace(/'/g, `'\\''`);
return await new Promise( (resolve) => {
exec('htpasswd -bnB admin \''+password+'\' | cut -sd \':\' -f2', (error, stdout, stderr) => {
if (error) {
return resolve(null);
}
// remove newline at the end
resolve(stdout.substr(0,stdout.length-1));
});
});
};