Skip to content

Instantly share code, notes, and snippets.

@Darkflib
Created November 8, 2013 11:37
Show Gist options
  • Save Darkflib/7369802 to your computer and use it in GitHub Desktop.
Save Darkflib/7369802 to your computer and use it in GitHub Desktop.
motp in php
<?php
/*
php-fuction to validate
Mobile One Time Passwords
by Ralf Neumann (ralf@njumaen.de)
based on
motp.sourceforge.net
*/
function checkOTP($pin,$otp,$initsecret)
{
$maxperiod = 3*60; // in seconds = +/- 3 minutes
$time=gmdate("U");
for($i = $time - $maxperiod; $i <= $time + $maxperiod; $i++)
{
$md5 = substr(md5(substr($i,0,-1).$initsecret.$pin),0,6);
if($otp == $md5) return(true);
}
return(false);
}
?>
@Darkflib
Copy link
Author

Darkflib commented Nov 8, 2013

$initsecret = 16 digit hex

need to step by 10 rather than 1 in loop. 10x speed up ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment