diff --git a/lib/GoogleAuthenticator.php b/lib/GoogleAuthenticator.php index 344c034..7ed840f 100644 --- a/lib/GoogleAuthenticator.php +++ b/lib/GoogleAuthenticator.php @@ -11,10 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. - include_once("FixedByteNotation.php"); - class GoogleAuthenticator { static $PASS_CODE_LENGTH = 6; static $PIN_MODULO; @@ -32,20 +30,17 @@ public function checkCode($secret,$code) { return true; } } - return false; - } public function getCode($secret,$time = null) { - if (!$time) { $time = floor(time() / 30); } $base32 = new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', TRUE, TRUE); $secret = $base32->decode($secret); - $time = pack("N", $time); + $time = pack('N', $time); $time = str_pad($time,8, chr(0), STR_PAD_LEFT); $hash = hash_hmac('sha1',$time,$secret,true); @@ -59,30 +54,23 @@ public function getCode($secret,$time = null) { protected function hashToInt($bytes, $start) { $input = substr($bytes, $start, strlen($bytes) - $start); - $val2 = unpack("N",substr($input,0,4)); + $val2 = unpack('N',substr($input,0,4)); return $val2[1]; } public function getUrl($user, $hostname, $secret) { - $url = sprintf("otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret); - $encoder = "https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl="; - $encoderURL = sprintf( "%sotpauth://totp/%s@%s&secret=%s",$encoder, $user, $hostname, $secret); - + $encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl="; + $encoderURL = $encoder . urlencode("otpauth://totp/{$user}@{$hostname}?secret={$secret}&issuer={$name}"); return $encoderURL; - } public function generateSecret() { - $secret = ""; - for($i = 1; $i<= self::$SECRET_LENGTH;$i++) { + $secret = null; + for($i = 1;$i<= self::$SECRET_LENGTH;$i++) { $c = rand(0,255); $secret .= pack("c",$c); } $base32 = new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', TRUE, TRUE); return $base32->encode($secret); - - } - } -