Example #1
0
 public function login()
 {
     $this->pass = parent::encrypt($this->pass);
     $select = DataBase::connect()->prepare("select * from client where login=:login and pass=:pass");
     $ex = $select->execute(array('login' => $this->login, 'pass' => $this->pass));
     $e = $select->rowCount();
     if ($e > 0) {
         while ($line = $select->fetch(PDO::FETCH_OBJ)) {
             $this->id = $line->id_client;
         }
         session_start();
         $_SESSION["login"] = $this->login;
         $_SESSION["pass"] = $this->pass;
         $_SESSION["id"] = $this->id;
         header('location:compte.php');
     } else {
         return false;
     }
 }
<?php

include_once 'crypt.php';
$password = '******';
# can be genegated by crypt::rand()
$salt = 'the password salt';
# same
$key = crypt::pbkdf2($password, $salt);
# secret key
$message = 'secret message for humanity';
# message to hide
$encrypted = crypt::encrypt($message, $key);
# encrypt message, raw binary ciphertext returned
$decrypted = crypt::decrypt($encrypted, $key);
# decrypt the ciphertext, original variable returned
echo $decrypted;
# 'secret message for humanity'
Example #3
0
 private function generate()
 {
     $result = substr(base64_encode(rand()), 0, 6);
     return crypt::encrypt($result);
 }