├── README.md ├── api └── AuthFunctions.php └── index.php /README.md: -------------------------------------------------------------------------------- 1 | # SteamGenerateMobileAuthPHP 2 | Generate Steam Mobile Auth (2FA) Code using PHP. 3 | 4 | # Installation 5 | 6 | ``` 7 | require_once './api/AuthFunctions.php' 8 | ``` 9 | 10 | # Usage 11 | Instantiate a steam auth.. 12 | 13 | ```php 14 | $SteamAuth = new SteamAuth; 15 | ``` 16 | 17 | ...generating 2FA Code: 18 | 19 | ```php 20 | $SteamAuth->GenerateSteamGuardCode("Shared Secret Key"); 21 | ``` 22 | 23 | # Proof 24 | https://youtu.be/umoMBn_UTqg 25 | -------------------------------------------------------------------------------- /api/AuthFunctions.php: -------------------------------------------------------------------------------- 1 | intToByte($test); 20 | $intModeArray++; 21 | } 22 | return $mode; 23 | } 24 | 25 | function getSteamTime($localtime = false) 26 | { 27 | if($localtime) return time()+10; 28 | $data = array('steamid' => 0); 29 | $url = 'http://api.steampowered.com/ITwoFactorService/QueryTime/v0001'; 30 | $ch = curl_init($url); 31 | $postString = http_build_query($data, '', '&'); 32 | curl_setopt($ch, CURLOPT_POST, 1); 33 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); 34 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 35 | $response = curl_exec($ch); 36 | $response = json_decode($response); 37 | curl_close($ch); 38 | 39 | return $response->response->server_time; 40 | } 41 | 42 | function createTimeHash($time) 43 | { 44 | $time /= 30; 45 | $timeArray = array(); 46 | for($i = 8; $i > 0; $i--) 47 | { 48 | $timeArray[$i - 1] = $this->intToByte($time); 49 | $time >>= 8; 50 | } 51 | $timeArray = array_reverse($timeArray); 52 | $newTimeArray = ""; 53 | foreach($timeArray as $timeArrayValue) 54 | { 55 | $newTimeArray .= chr($timeArrayValue); 56 | } 57 | return $newTimeArray; 58 | } 59 | 60 | function createHMac($timeHash, $SharedSecretDecoded) 61 | { 62 | $hash = hash_hmac('sha1', $timeHash, $SharedSecretDecoded, false); 63 | $hmac = unpack('C*', pack('H*', $hash)); 64 | return $hmac; 65 | } 66 | 67 | function GenerateSteamGuardCode($shared_secret) 68 | { 69 | if($shared_secret == "Shared Secret Key") return "You need to change the 'Shared Secret Key' to your Shared Secret!"; 70 | $DecodedSharedSecret = base64_decode($shared_secret); 71 | $timeHash = $this->createTimeHash($this->getSteamTime(true)); // If you need Steam Time instead the local time, use 'false'. (Using local time the response time is less) 72 | $HMAC = $this->createHMac($timeHash, $DecodedSharedSecret); 73 | $HMAC = $this->startArrayToZero($HMAC); 74 | 75 | $b = $this->intToByte(($HMAC[19] & 0xF)); 76 | $codePoint = ($HMAC[$b] & 0x7F) << 24 | ($HMAC[$b+1] & 0xFF) << 16 | ($HMAC[$b+2] & 0xFF) << 8 | ($HMAC[$b+3] & 0xFF); 77 | 78 | $SteamChars = "23456789BCDFGHJKMNPQRTVWXY"; 79 | $code = ""; 80 | 81 | for($i = 0; $i < 5; $i++) 82 | { 83 | $code = $code."".$SteamChars{floor($codePoint) % strlen($SteamChars)}; 84 | $codePoint /= strlen($SteamChars); 85 | } 86 | return $code; 87 | } 88 | } 89 | 90 | ?> 91 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | GenerateSteamGuardCode("Shared Secret Key"); 12 | 13 | ?> --------------------------------------------------------------------------------