-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2FA.js
91 lines (83 loc) · 2.57 KB
/
2FA.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
This code was written by /u/-rocky- (https://www.reddit.com/user/-rocky-)
Source : https://www.reddit.com/r/SteamBot/comments/3v72zz/node_small_script_to_enable_and_confirm_2fa/
*/
var username;
var password;
var steamCode;
var fs = require("fs");
var SteamCommunity = require("steamcommunity");
var readline = require("readline");
var community = new SteamCommunity();
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Username: ", function (name) {
username = name;
rl.question("Password: ", function (pass) {
password = pass;
rl.pause();
login();
});
});
function login() {
community.login({
"accountName": username,
"password": password,
}, function (err, sessionId, cookies, steamguard) {
if (err) {
console.log(err);
rl.resume();
rl.question("SteamGuard code: ", function (answer) {
steamCode = answer;
rl.pause();
community.login({
"accountName": username,
"password": password,
"authCode": steamCode
}, function (err, sessionId, cookies, steamguard) {
if (err) {
console.log("Err after community login: " + err);
} else {
enable2fa();
}
});
});
} else {
enable2fa();
}
});
}
function enable2fa() {
community.enableTwoFactor(function (err, resp) {
if (err) {
console.log(err.message);
} else {
if (resp.status != 1) {
console.log("Failed: " + resp.status);
} else {
console.log(resp);
var shared_secret = resp.shared_secret;
fs.writeFile(username + ".2fa", JSON.stringify(resp), function (err) {
if (err) throw err;
console.log("Response saved as " + username + ".2fa");
rl.resume();
rl.question("Activation code: ", function (code) {
finalize2fa(shared_secret, code);
rl.close();
});
});
}
}
});
}
function finalize2fa(shared_secret, code) {
community.finalizeTwoFactor(shared_secret, code, function (err) {
if (err) {
console.log(err);
} else {
console.log("2FA finalized successfully");
}
});
}