当前位置: 首页>>代码示例>>PHP>>正文


PHP PasswordHash::slow_equals方法代码示例

本文整理汇总了PHP中PasswordHash::slow_equals方法的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash::slow_equals方法的具体用法?PHP PasswordHash::slow_equals怎么用?PHP PasswordHash::slow_equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PasswordHash的用法示例。


在下文中一共展示了PasswordHash::slow_equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate_password

 public function validate_password($password, $correct_hash)
 {
     $params = explode(":", $correct_hash);
     if (count($params) < HASH_SECTIONS) {
         return false;
     }
     $pbkdf2 = base64_decode($params[HASH_PBKDF2_INDEX]);
     return PasswordHash::slow_equals($pbkdf2, PasswordHash::pbkdf2($params[HASH_ALGORITHM_INDEX], $password, $params[HASH_SALT_INDEX], (int) $params[HASH_ITERATION_INDEX], strlen($pbkdf2), true));
 }
开发者ID:croger46,项目名称:oceanicdestiny,代码行数:9,代码来源:passwordHash.php

示例2: die

<?php

require_once 'db.php';
require_once 'PasswordHashClass.php';
# Make sure params are in place or die!
if (!isset($_GET['user']) || !isset($_GET['key'])) {
    die("Missing some parameters here");
}
$db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
# Retrieve user data
$userCheck = $db->prepare("SELECT * FROM ovr_lists_login WHERE user_id = :id");
$userCheck->bindParam(':id', $_GET['user'], PDO::PARAM_INT);
$userCheck->execute();
if ($userCheck->rowCount() == 1) {
    $user = $userCheck->fetch(PDO::FETCH_ASSOC);
    $activation_hash_string = $user['user_id'] . $user['user_name'] . $user['user_email'] . $user['user_password_hash'];
    $generatedActivation = urlencode(hash_hmac('sha256', $activation_hash_string, $user['user_password_hash']));
    if (PasswordHash::slow_equals($generatedActivation, $_GET['key']) == 1) {
        $activateUser = $db->prepare("UPDATE ovr_lists_login SET activated = '1' WHERE user_id = :id");
        $activateUser->bindParam(':id', $_GET['user'], PDO::PARAM_INT);
        if ($activateUser->execute()) {
            echo "<h1>Activation successful</h1>";
        } else {
            echo "<h1 style='color:red'>Activation failed</h1>";
        }
    }
}
开发者ID:NerdyDillinger,项目名称:ovrride,代码行数:27,代码来源:activate.php

示例3: PDO

require_once 'PasswordHashClass.php';
require_once 'db.php';
require_once 'Mandrill.php';
$db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
if (isset($_POST['key']) && isset($_POST['user_id'])) {
    $hashCheck = $db->prepare("SELECT * FROM ovr_lists_login WHERE user_id = :id");
    $hashCheck->bindParam("id", $_POST['user_id'], PDO::PARAM_STR);
    $hashCheck->execute();
    if ($hashCheck->rowCount() !== 1) {
        echo "Something went wrong, please try again.";
    } else {
        $user = $hashCheck->fetch(PDO::FETCH_ASSOC);
        $hash_string = $user['user_id'] . $user['user_name'] . $user['user_email'] . $user['user_password_hash'];
        $reset_hash = urlencode(hash_hmac('sha256', $hash_string, $user['user_password_hash']));
        if (PasswordHash::slow_equals($_POST['key'], $reset_hash) == 1) {
            $hashed_password = PasswordHash::create_hash($_POST['user_password']);
            $passwordReset = $db->prepare("UPDATE ovr_lists_login SET user_password_hash = :password_hash, activated = '1' WHERE user_id = :id");
            if ($passwordReset->execute(array("password_hash" => $hashed_password, "id" => $_POST['user_id']))) {
                echo "Password has been reset go to <a href='https://{$_SERVER['SERVER_NAME']}/login/login.php'>https://{$_SERVER['SERVER_NAME']}/login/login.php</a> to login";
            } else {
                echo "Password failed to update.";
            }
        }
    }
} else {
    if (isset($_POST['Reset']) && $_POST['user_name'] && isset($_POST['user_email'])) {
        $userCheck = $db->prepare("SELECT * FROM ovr_lists_login WHERE user_name = :user AND user_email = :email");
        $userCheck->bindParam("user", $_POST['user_name'], PDO::PARAM_STR);
        $userCheck->bindParam("email", $_POST['user_email'], PDO::PARAM_STR);
        $userCheck->execute();
开发者ID:NerdyDillinger,项目名称:ovrride,代码行数:30,代码来源:reset.php


注:本文中的PasswordHash::slow_equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。