Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var SteamCommunity = require('steamcommunity');
  2. var SteamStore = require('steamstore');
  3. var ReadLine = require('readline');
  4. var fs = require('fs');
  5.  
  6. var community = new SteamCommunity();
  7. var store = new SteamStore();
  8. var rl = ReadLine.createInterface({
  9.     "input": process.stdin,
  10.     "output": process.stdout
  11. });
  12.  
  13. rl.question("Username: ", function(accountName) {
  14.     rl.question("Password: ", function(password) {
  15.         doLogin(accountName, password);
  16.     });
  17. });
  18.  
  19. function doLogin(accountName, password, authCode, captcha) {
  20.     community.login({
  21.         "accountName": accountName,
  22.         "password": password,
  23.         "authCode": authCode,
  24.         "captcha": captcha
  25.     }, function(err, sessionID, cookies, steamguard) {
  26.         if(err) {
  27.             if(err.message == 'SteamGuardMobile') {
  28.                 console.log("This account already has two-factor authentication enabled.");
  29.                 process.exit();
  30.                 return;
  31.             }
  32.  
  33.             if(err.message == 'SteamGuard') {
  34.                 console.log("An email has been sent to your address at " + err.emaildomain);
  35.                 rl.question("Steam Guard Code: ", function (code) {
  36.                     doLogin(accountName, password, code);
  37.                 });
  38.  
  39.                 return;
  40.             }
  41.  
  42.             if(err.message == 'CAPTCHA') {
  43.                 console.log(err.captchaurl);
  44.                 rl.question("CAPTCHA: ", function(captchaInput) {
  45.                     doLogin(accountName, password, authCode, captchaInput);
  46.                 });
  47.  
  48.                 return;
  49.             }
  50.  
  51.             console.log(err);
  52.             process.exit();
  53.             return;
  54.         }
  55.  
  56.         promptPhoneNumber(cookies);
  57.        
  58.  
  59.        
  60.  
  61.  
  62.  
  63.     });
  64. }
  65.  
  66. function promptActivationCode(response) {
  67.     rl.question("SMS Code: ", function(smsCode) {
  68.         community.finalizeTwoFactor(response.shared_secret, smsCode, function(err) {
  69.             if(err) {
  70.                 if(err.message == "Invalid activation code") {
  71.                     console.log(err);
  72.                     promptActivationCode(response);
  73.                     return;
  74.                 }
  75.  
  76.                 console.log(err);
  77.             } else {
  78.                 console.log("Two-factor authentication enabled!");
  79.             }
  80.  
  81.             process.exit();
  82.         });
  83.     });
  84. }
  85.  
  86. function promptPhoneNumber(cookies) {
  87.     store.setCookies(cookies);
  88.     rl.question("Phone Number: ", function(phoneNumber) {
  89.         store.addPhoneNumber(phoneNumber,true,function(err) {
  90.             if(err) {
  91.                 console.log("error adding phone number, assuming it already has one");
  92.                 enable2fa();
  93.  
  94.             } else {
  95.                 rl.question("Confirmation Code: ", function(confirmationCode) {
  96.                     store.verifyPhoneNumber(confirmationCode,function(err) {
  97.                         if(!err) {
  98.                             setTimeout(function(){
  99.                                 enable2fa();
  100.                             },30000);
  101.                         }
  102.                     });
  103.                 });
  104.             }
  105.         });
  106.     });
  107. }
  108.  
  109.  
  110. function enable2fa() {
  111.     community.enableTwoFactor(function(err, response) {
  112.     if(err) {
  113.         if(err.eresult == 2) {
  114.             console.log("Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?");
  115.             process.exit();
  116.             return;
  117.         }
  118.  
  119.         if(err.eresult == 84) {
  120.             console.log("Error: RateLimitExceeded. Try again later.");
  121.             process.exit();
  122.             return;
  123.         }
  124.  
  125.         console.log(err);
  126.         process.exit();
  127.         return;
  128.     }
  129.  
  130.     if(response.status != 1) {
  131.         console.log("Error: Status " + response.status);
  132.         process.exit();
  133.         return;
  134.     }
  135.  
  136.     console.log("Writing secrets to twofactor_" + community.steamID.getSteamID64() + ".json");
  137.     console.log("Revocation code: " + response.revocation_code);
  138.     fs.writeFile("twofactor_" + community.steamID.getSteamID64() + ".json", JSON.stringify(response, null, "\t"));
  139.  
  140.     promptActivationCode(response);
  141. });
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement