validate_password() public méthode

public validate_password ( $password )
Exemple #1
0
 function show($id, $password)
 {
     $conf = get_config();
     $template = $this->template;
     if (!empty($_COOKIE['theme'])) {
         $template->assign('theme', $_COOKIE['theme']);
     }
     //print_r( $_COOKIE );
     // This may be required if a user is dealing with a file that is so large that is takes more than 30 seconds
     set_time_limit(0);
     require_once __DIR__ . '/paste.class.php';
     $pastes = new Paste();
     $paste = $pastes->get($id);
     // detect if any errors came through
     switch ($paste) {
         case NCRYPT_DOES_NOT_EXIST:
         case NCRYPT_HAS_EXPIRED:
         case NCRYPT_MISSING_DATA:
             $template->assign('meta_title', $conf['site']['name'] . ' - Paste does not exist');
             $template->render(404, 'nonexistant.tpl');
             return;
     }
     // validate paste, check if password has been set
     $validated = $pastes->validate_password($paste, $password);
     switch ($validated) {
         case NCRYPT_PASSWORD_FAILED:
             // incorrect, give the json response an error
         // incorrect, give the json response an error
         case NCRYPT_PASSWORD_REQUIRED:
             // prompt user for password
             $template->assign('meta_title', $conf['site']['name'] . ' - Paste requires password');
             $template->render(403, 'paste.tpl');
             break;
         case NCRYPT_PASSWORD_SUCCESS:
             // correct, send user the required data
         // correct, send user the required data
         case NCRYPT_NO_PASSWORD:
             // no password, show paste
             if ('html' !== $template->format()) {
                 $output = $pastes->read($paste);
             } else {
                 // read paste via javascript to make basic page loading faster
                 $output = array();
             }
             $template->assign('meta_title', $conf['site']['name'] . ' - Paste');
             $template->render(200, 'paste.tpl', $output);
             break;
         default:
             throw new Exception('Internal error');
     }
 }