hardlounge/src/command-line/reset.js

39 lines
983 B
JavaScript
Raw Normal View History

2014-10-03 09:57:35 +00:00
var bcrypt = require("bcrypt-nodejs");
2014-09-11 21:00:08 +00:00
var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
var Helper = require("../helper");
2014-09-11 21:00:08 +00:00
program
.command("reset <name>")
.description("Reset user password")
.action(function(name) {
var users = new ClientManager().getUsers();
if (users.indexOf(name) === -1) {
console.log("");
console.log("User '" + name + "' doesn't exist.");
console.log("");
return;
}
var file = Helper.HOME + "/users/" + name + ".json";
2014-09-11 21:00:08 +00:00
var user = require(file);
require("read")({
2014-09-14 00:09:21 +00:00
prompt: "Password: ",
silent: true
2014-09-11 21:00:08 +00:00
}, function(err, password) {
console.log("");
if (err) {
return;
}
2014-10-03 09:57:35 +00:00
var salt = bcrypt.genSaltSync(8);
var hash = bcrypt.hashSync(password, salt);
2014-09-11 21:00:08 +00:00
user.password = hash;
fs.writeFileSync(
file,
JSON.stringify(user, null, " ")
2014-09-11 21:00:08 +00:00
);
console.log("Successfully reset password for '" + name + "'.");
console.log("");
});
});