Beispiel #1
0
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Example page</title>
    </head>
    <body>
        <h2>This is an example page</h2>
        <h4>Look at the source code for this page if you want to learn how to use the Auth lib.</h4>
        <?php 
include_once 'lib/Auth/Encryption.php';
include_once 'lib/Auth/Config.php';
$salt = Encryption::generateSalt("hashing");
$encrypted = Encryption::generateHash("asd", $salt);
echo "Hashed: " . $encrypted . "<br>";
$verify = Encryption::verifyHash("asd" . $salt, $encrypted);
echo "Verified: ";
if ($verify == true) {
    echo "true";
} elseif ($verify == false) {
    echo "false";
}
?>
    </body>
</html>
Beispiel #2
0
}
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$filename = $_FILES['file']['name'];
if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
    $tmpName = $_FILES['file']['tmp_name'];
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    $password = NULL;
    if ($_POST['password'] != "") {
        include 'lib/Encryption.php';
        $salt = Encryption::generateSalt();
        $content = Encryption::encrypt($content, $_POST['password'], $salt);
        $password = $_POST['password'];
        $filename = Encryption::encrypt($filename, $_POST['password'], $salt);
    }
    $name = getName(10, 20, "name") . "." . $extension;
    $rmcode = getName(32, 64, "removalcode");
    $options = array('cost' => 12);
    require __DIR__ . "/lib/password.php";
    $hashrmcode = password_hash($rmcode, PASSWORD_BCRYPT, $options);
    $q = "INSERT INTO `" . $config['mysql-table'] . "` (`name`, `size`, `type`, `content`, `file-name`, `removalcode`) VALUES (?, ?, ?, ?, ?, ?);";
    $query = $database->prepare($q);
    $query->bind_param("ssssss", $name, $_FILES['file']['size'], $_FILES['file']['type'], $content, $filename, $hashrmcode);
    $query->execute();
    if ($_POST['password'] != "") {
        $m = $database->prepare("UPDATE `" . $config['mysql-table'] . "` SET `salt`=?, `encryption`=? WHERE `name`=?");