-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeUser.js
77 lines (63 loc) · 2.28 KB
/
makeUser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// utility to create Homebrew (initial root) user interactively...
// modify to add/change 'other' fields as necessary
const crypto = require('crypto');
const bcrypt = require('bcryptjs');
const readline = require('readline');
const hash = (msg,algo='sha256',enc='hex') => crypto.createHash(algo).update(msg).digest(enc);
const rd = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function ask(prompt) {
return new Promise((resolve,reject)=>{rd.question(prompt,(answer)=> resolve(answer))})
};
(async function() {
let user = {
username: '',
credentials: {
hash: '',
pin: '',
passcode : {},
},
member: '',
fullname: '',
email: '',
phone: '',
other: { //customize as necessary
account: '',
location: '',
unit: '',
tag: ''
},
status: 'INACTIVE'
};
ITERATIONS = 11;
console.log('Enter credentials and permissions...');
user.username = await ask('Enter the username: ');
let pw = await ask('Enter a password: ');
let test = await ask('Enter an optional challenge: ');
user.pin = (await ask('Enter a pin[1234]: ')) || 1234;
user.member = await ask('Enter group membership permissions (i.e. users,cms,...): ');
user.status = (await ask('Enter user status[ACTIVE](i.e. PENDING,ACTIVE,INACTIVE): ')) || 'ACTIVE';
console.log('\nEnter identification...');
user.fullname = await ask('Enter user\'s fullname: ');
user.email = await ask('Enter email: ');
user.phone = await ask('Enter phone: ');
console.log('\nEnter other data...');
for (let x of Object.keys(user.other)) {
user.other[x] = await ask(`Enter ${x}: `);
};
// build...
user.credentials.oldHash = bcrypt.hashSync(hash(user.username+pw),8);
user.credentials.hash = bcrypt.hashSync(pw, ITERATIONS);
console.log(JSON.stringify(user));
console.log(JSON.stringify(user,null,2));
if (test) {
let check = {
pw: bcrypt.compareSync(pw,test),
old: bcrypt.compareSync(hash(user.username+pw),test)
};
console.log('check: ', check);
};
rd.close();
})().catch(e=>console.error(e));