now() public method

public now ( )
 /**
  * Get the one time code for the otp instance
  * @param TOTP|null $totp
  * @return mixed
  */
 public function getCode(TOTP $totp = null)
 {
     if ($totp !== null) {
         return $totp->now();
     } else {
         return $this->totp->now();
     }
 }
Exemplo n.º 2
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = OTPGen::LoadConfig();
     $keyArgument = $input->getArgument('name');
     if (!key_exists($keyArgument, $config) && !is_numeric($keyArgument)) {
         $output->writeln('The entry ' . $keyArgument . ' does not exist in your library. Add it by using the add command.');
         return 0;
     }
     if (is_numeric($keyArgument)) {
         if (intval($keyArgument) > count($config) - 1) {
             $output->writeln('There is no entry in your library with the id: ' . $keyArgument . '.');
             return 0;
         }
         $count = 0;
         foreach ($config as $key => $WhyBother) {
             if ($count == intval($keyArgument)) {
                 $keyArgument = $key;
                 continue;
             }
             $count++;
         }
     }
     $totp = new TOTP();
     $totp->setDigits($config[$keyArgument]['size'])->setDigest($config[$keyArgument]['digest'])->setInterval($config[$keyArgument]['interval'])->setSecret($config[$keyArgument]['token']);
     $output->writeln('Your token is: <options=bold>' . $totp->now() . '</>');
     return 0;
 }
 public function testNow()
 {
     $totp = new TOTP('JDDK4U6G3BJLEZ7Y');
     $this->assertEquals($totp->at(time()), $totp->now());
 }