Example #1
0
 function confirm()
 {
     $code = request::post('pppcode')->toString();
     $user = session::get('username');
     if ($code) {
         if (User::authenticate(new PppAuthentication($user, (string) $code))) {
             printf('<h1>Success.</h1>');
             return;
         } else {
             printf('Failure');
         }
     }
     $code = PppAuthentication::getNextIdentifier($user);
     printf('<form action="/ppp/confirm" method="post">');
     printf('<p>Enter code <b>%s</b>: <input type="text" name="pppcode"></p>', PppAuthentication::cardIndexToString($code));
     printf('<p><input type="submit"></p>');
     printf('</form>');
 }
Example #2
0
 function ppp($command = null)
 {
     $args = func_get_args();
     $args = array_slice($args, 1);
     using('lepton.user.providers.ppp');
     switch ($command) {
         case 'genkey':
             if (count($args) > 0) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[0]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[0]);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
             }
             console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             break;
         case 'printcard':
             if (count($args) > 1) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[1]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[1]);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
             }
             console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             if (count($args) > 0) {
                 $card = intval($args[0]) - 1;
             } else {
                 $card = 0;
             }
             PppAuthentication::printPasswordCard($key, 4, $card);
             break;
         case 'printcode':
             if (count($args) > 2) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[2]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[2]);
                 console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
                 console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             }
             if (count($args) > 1) {
                 $card = $args[0];
                 $code = $args[1];
             } else {
                 $card = 0;
                 $code = 1;
             }
             console::writeLn(PppAuthentication::getCode($key, $code, 4));
             break;
         case 'getlotto':
             $key = PppAuthentication::generateRandomSequenceKey();
             $code = rand(0, 65535);
             console::writeLn(PppAuthentication::getLotto($key, $code));
             break;
         case 'tostring':
             if (count($args) > 0) {
                 console::writeLn(PppAuthentication::cardIndexToString($args[0]));
             } else {
                 console::writeLn("Not enough parameters.");
             }
             break;
         case '':
             console::writeLn(__astr("ppp \\b{printcard} [\\u{card} [\\u{key}]]   -- Print a specific card (with specific key)"));
             console::writeLn(__astr("ppp \\b{printcode} [\\u{card} \\u{code} [\\u{key}]]   -- Print code from card"));
             console::writeLn(__astr("ppp \\b{genkey} [\\u{string}]   -- Generate key (from string)"));
             console::writeLn(__astr("ppp \\b{getlotto}   -- return lotto numbers"));
             console::writeLn(__astr("ppp \\b{tostring} \\u{code}   -- return string representation of code index"));
             break;
         default:
             console::writeLn("Bad command.");
     }
 }