/**
  * @Route("/ajax/teacher", name="ajax_delete")
  */
 public function teacherAction(Request $request)
 {
     $session = $request->getSession();
     if ($session->get('admin', false)) {
         $generator = new SecureRandom();
         $random = $generator->nextBytes(8);
         $email = $_POST['email'];
         $key = bin2hex($random);
         $con = self::connect();
         $query = "INSERT INTO pem (`key`, `email`) VALUES (?,?)";
         $stmt = $con->prepare($query);
         $stmt->bind_param('ss', $key, $email);
         $stmt->execute();
         $result = $stmt->affected_rows > 0;
         if ($result) {
             $link = "http://*****:*****@gmail.com')->setTo($email)->setBody($this->renderView('Emails/teacher.html.twig', array('key' => $key, 'link' => $link)), 'text/html');
             $this->get('mailer')->send($message);
             return new JsonResponse(array('status' => 200, 'message' => "Email sent!"));
         } else {
             return new JsonResponse(array('status' => 400, 'message' => "Error processing request. Please try again."));
         }
     } else {
         throw new HttpException(401, 'Unauthorized access.');
     }
 }
Beispiel #2
0
 /**
  * @expectedException Exception
  */
 public function testWithoutStrongCryptographicNumber()
 {
     SecureRandom::generateRandom(0);
 }
Beispiel #3
0
function pkcs1pad2($s, $n)
{
    if ($n < strlen($s) + 11) {
        echo "Message too long for RSA";
        return null;
    }
    $ba = array();
    $i = strlen($s) - 1;
    while ($i >= 0 && $n > 0) {
        $ba[--$n] = ord($s[$i--]);
    }
    $ba[--$n] = 0;
    $rng = new SecureRandom($GLOBALS['rngc']);
    $x = array();
    while ($n > 2) {
        // random non-zero pad
        $x[0] = 0;
        while ($x[0] == 0) {
            $rng->nextBytes($x);
        }
        $ba[--$n] = $x[0];
    }
    $ba[--$n] = 2;
    $ba[--$n] = 0;
    return new BigInteger($ba);
}