本文整理汇总了PHP中PasswordHash::CheckPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash::CheckPassword方法的具体用法?PHP PasswordHash::CheckPassword怎么用?PHP PasswordHash::CheckPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PasswordHash
的用法示例。
在下文中一共展示了PasswordHash::CheckPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LoginUser
/**
* Logs in a user. Returns boolean indicating the result.
*
* @param string $userName Username of the person logging in.
* @param string $password Password in plain text of the person logging in.
**/
function LoginUser($userName, $password)
{
if ($stmt = $this->dbConnect->prepare("SELECT password FROM usersinfo WHERE username=?")) {
$stmt->bind_param("s", $userName);
$stmt->execute();
$stmt->bind_result($hashedPassword);
$stmt->fetch();
$stmt->close();
$pwdHasher = new PasswordHash(8, FALSE);
$hashString = $pwdHasher->HashPassword($password);
// Tests to determine if hashing is the issue with the login problem.
/*
$hashString = $pwdHasher->HashPassword($password);
echo "The password entered is " . $password . "<br />";
echo "The hashed string is " . $hashString . "<br />";
echo "The hashed password to compare against is " . $hashedPassword;
*/
//if($pwdHasher->CheckPassword($password, $hashedPassword))
if ($pwdHasher->CheckPassword($hashString, $hashedPassword)) {
}
echo $userName;
$_SESSION['username'] = $userName;
return true;
}
return false;
}
示例2: checkPassword
function checkPassword($password)
{
switch ($this->userData['passwordFormat']) {
case 'phpass':
if (!isset($this->userData['passwordHash'])) {
throw new Exception('User object was not generated with password hash information.');
} else {
require 'PasswordHash.php';
$h = new PasswordHash(8, FALSE);
return $h->CheckPassword($password, $this->userData['passwordHash']);
}
break;
case 'vbmd5':
if (!isset($this->userData['passwordHash'], $this->userData['passwordSalt'])) {
throw new Exception('User object was not generated with password hash information.');
} else {
if ($this->userData['passwordHash'] === md5($password . $this->userData['passwordSalt'])) {
return true;
} else {
return false;
}
}
break;
case 'raw':
if ($this->userData['passwordHash'] === md5($password . $this->userData['passwordSalt'])) {
return true;
} else {
return false;
}
break;
default:
throw new Exception('Invalid password format.');
break;
}
}
示例3: login
/**
* Log the user in
*
* @param string
* @param string
* @return bool
*/
function login($username, $password)
{
if (is_null($user = $this->ci->user_dal->get_user_by_username($username))) {
$this->increase_login_attempt($username);
$this->error = array('msg' => "Login incorrect");
return FALSE;
}
$hasher = new PasswordHash(8, FALSE);
if (!$hasher->CheckPassword($password, $user->password)) {
$this->increase_login_attempt($username);
$this->error = array('msg' => "Login incorrect");
return FALSE;
}
if ($user->banned == 1) {
$this->error = array('msg' => $user->ban_reason);
return FALSE;
}
if ($user->activated == 0) {
$this->error = array('msg' => "User Account is not active");
return FALSE;
}
$data = array('user_id' => $user->id, 'username' => $user->username, 'status' => $user->activated == 1 ? 1 : 0, 'threads_shown' => $user->threads_shown, 'hide_enemy_posts' => $user->hide_enemy_posts, 'comments_shown' => $user->comments_shown, 'view_html' => $user->view_html, 'new_post_notification' => $user->new_post_notification, 'random_titles' => $user->random_titles, 'emoticon' => $user->emoticon, 'hide_ads' => $user->hide_ads, 'chat_fixed_size' => $user->chat_fixed_size);
$this->ci->session->set_userdata($data);
$this->ci->user_id = (int) $user->id;
$this->create_autologin($user->id);
$this->ci->user_dal->insert_ip_address($user->id, $this->ci->input->ip_address());
$this->clear_login_attempts($username);
$ip = $this->ci->config->item('login_record_ip', 'auth');
$time = $this->ci->config->item('login_record_time', 'auth');
$this->ci->user_dal->update_login_info($user->id, $ip, $time);
return TRUE;
}
示例4: login
public function login($user, $password)
{
$userslug = makeSlug($user);
$tablename = $this->prefix . "users";
// for once we don't use getUser(), because we need the password.
$user = $this->db->fetchAssoc("SELECT * FROM {$tablename} WHERE username='{$userslug}'");
if (empty($user)) {
$this->session->setFlash('error', 'Username or password not correct. Please check your input.');
return false;
}
require_once __DIR__ . "/phpass/PasswordHash.php";
$hasher = new PasswordHash(8, TRUE);
if ($hasher->CheckPassword($password, $user['password'])) {
if (!$user['enabled']) {
$this->session->setFlash('error', 'Your account is disabled. Sorry about that.');
return false;
}
$update = array('lastseen' => date('Y-m-d H:i:s'), 'lastip' => $_SERVER['REMOTE_ADDR']);
$this->db->update($tablename, $update, array('id' => $user['id']));
$user = $this->getUser($user['id']);
$this->session->start();
$this->session->set('user', $user);
$this->session->setFlash('success', "You've been logged on successfully.");
return true;
} else {
$this->session->setFlash('error', 'Username or password not correct. Please check your input.');
return false;
}
}
示例5: correct_credentials
function correct_credentials($username, $password)
{
$rightPassword = false;
try {
// Pull in the password hash from the DB for this user
$db = new PDO("sqlite:database/noiseFactionDatabase.db");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("select passwordHash from Account where username = ?;");
$result = $statement->execute(array($username));
if ($result != 1) {
throw new pdoDbException("Something's gone wrong with the prepared statement");
} else {
$userTuple = $statement->fetch(PDO::FETCH_ASSOC);
// If $userTuple is null, there is no account under that name
if ($userTuple !== null) {
$passwordHash = $userTuple["passwordHash"];
$hasher = new PasswordHash(8, FALSE);
// This comes from PasswordHash.php
$rightPassword = $hasher->CheckPassword($attempt, $passwordHash);
} else {
// What should we do here?
$rightPassword = false;
}
}
$db = null;
} catch (PDOException $e) {
echo 'Exception: ' . $e->getMessage();
}
return $rightPassword;
}
示例6: _authenticate
private function _authenticate($queryWhereCondition, $loginStr, $password)
{
// query user in Joomla table
$result = $this->_db->querySelect('user_login,user_email,user_pass', $this->_websoccer->getConfig('wordpresslogin_tableprefix') . 'users', 'user_status = 0 AND ' . $queryWhereCondition, $loginStr);
$wpUser = $result->fetch_array();
$result->free();
// user does not exist
if (!$wpUser) {
return FALSE;
}
// check password.
require BASE_FOLDER . '/classes/phpass/PasswordHash.php';
$hasher = new PasswordHash(8, TRUE);
if (!$hasher->CheckPassword($password, $wpUser['user_pass'])) {
return FALSE;
}
// valid user, check if he exists
$userEmail = strtolower($wpUser['user_email']);
$userId = UsersDataService::getUserIdByEmail($this->_websoccer, $this->_db, $userEmail);
if ($userId > 0) {
return $userId;
}
// create new user
return UsersDataService::createLocalUser($this->_websoccer, $this->_db, $wpUser['user_login'], $userEmail);
}
示例7: txp_validate
function txp_validate($user, $password, $log = TRUE)
{
$safe_user = doSlash($user);
$name = FALSE;
$hash = safe_field('pass', 'txp_users', "name = '{$safe_user}'");
$phpass = new PasswordHash(PASSWORD_COMPLEXITY, PASSWORD_PORTABILITY);
// check post-4.3-style passwords
if ($phpass->CheckPassword($password, $hash)) {
if ($log) {
$name = safe_field("name", "txp_users", "name = '{$safe_user}' and privs > 0");
} else {
$name = $user;
}
} else {
// no good password: check 4.3-style passwords
$passwords = array();
$passwords[] = "password(lower('" . doSlash($password) . "'))";
$passwords[] = "password('" . doSlash($password) . "')";
if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
$passwords[] = "old_password(lower('" . doSlash($password) . "'))";
$passwords[] = "old_password('" . doSlash($password) . "')";
}
$name = safe_field("name", "txp_users", "name = '{$safe_user}' and (pass = " . join(' or pass = ', $passwords) . ") and privs > 0");
// old password is good: migrate password to phpass
if ($name !== FALSE) {
safe_update("txp_users", "pass = '" . doSlash($phpass->HashPassword($password)) . "'", "name = '{$safe_user}'");
}
}
if ($name !== FALSE && $log) {
// update the last access time
safe_update("txp_users", "last_access = now()", "name = '{$safe_user}'");
}
return $name;
}
示例8: PasswordHash
function phpass_check($user, $auth)
{
$CI =& get_instance();
$CI->load->library('PasswordHash');
$hasher = new PasswordHash(HASH_COST_LOG2, HASH_PORTABLE);
return $hasher->CheckPassword($auth['password'], $user['password']);
}
示例9: validateUserPass
/**
* Validates a username and password
*
* This method should return true or false depending on if login
* succeeded.
*
* @param string $username
* @param string $password
*
* @return bool
*/
protected function validateUserPass($username, $password)
{
$linkItem = \OCP\Share::getShareByToken($username, false);
\OC_User::setIncognitoMode(true);
$this->share = $linkItem;
if (!$linkItem) {
return false;
}
// check if the share is password protected
if (isset($linkItem['share_with'])) {
if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
// Check Password
$forcePortable = CRYPT_BLOWFISH != 1;
$hasher = new \PasswordHash(8, $forcePortable);
if (!$hasher->CheckPassword($password . $this->config->getSystemValue('passwordsalt', ''), $linkItem['share_with'])) {
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return true;
}
}
示例10: compareHashedStrings
/**
* Given the plain password to check and a hash, returns true if there is
* a match.
*
* @param string $passwordToCheck
* @param string $hashedPassword
* @return boolean
*/
public static function compareHashedStrings($passwordToCheck, $hashedPassword)
{
// Get an instance of the pass hasher
$hasher = new PasswordHash(self::HASH_COST, self::HASH_PORTABILITY);
// Compare passwords
return $hasher->CheckPassword($passwordToCheck, $hashedPassword);
}
示例11: authenticate
public function authenticate()
{
$passwordHasher = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
if (null === $this->_user) {
$this->errorCode = self::ERROR_NOT_FOUND;
} else {
if (User::DISABLED === $this->_user->status) {
$this->errorCode = self::ERROR_DISABLED;
} else {
if (null === $this->_user->password_hash) {
$this->errorCode = self::ERROR_PASSWORD_NOT_SET;
} else {
if ($passwordHasher->CheckPassword($this->_user->password_hash, $this->_password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->errorCode = self::ERROR_NONE;
}
}
}
}
if (self::ERROR_NONE !== $this->errorCode) {
return $this->errorCode;
}
$this->setState('isAdmin', $this->_user->is_admin);
return self::ERROR_NONE;
}
示例12: check_login
function check_login($user_id, $password)
{
session_destroy();
session_start();
$wp_host = "127.0.0.1";
$wp_port = "3306";
$wp_user = "root";
$wp_pass = "root";
$wp_db = "jol";
$wp_conn = mysql_connect($wp_host . ":" . $wp_port, $wp_user, $wp_pass);
//$password=HashPassword($password);
$ret = false;
$wp_pre = "wp_";
$sql = "select * from " . $wp_pre . "users where user_login='" . mysql_real_escape_string($user_id) . "'";
if ($wp_conn) {
mysql_select_db($wp_db, $wp_conn);
$result = mysql_query($sql, $wp_conn);
$row = mysql_fetch_array($result);
if ($row) {
$wp_hasher = new PasswordHash(8, TRUE);
if ($wp_hasher->CheckPassword($password, $row['user_pass'])) {
$ret = $user_id;
$sql = "insert into users(user_id,ip,nick,school) values('" . mysql_real_escape_string($user_id) . "','','','') on DUPLICATE KEY UPDATE nick='" . mysql_real_escape_string($user_id) . "'";
mysql_query($sql);
}
}
}
return $ret;
}
示例13: login
function login($login, $password)
{
if (strlen($login) > 0 and strlen($password) > 0) {
$get_user_func = 'get_user_by_username';
//使用用户名查询验证
if (!is_null($user = $this->ci->admins->{$get_user_func}($login))) {
// 密码是否在数据库加密
$hasher = new PasswordHash($this->ci->config->item('phpass_hash_strength', 'fx_auth'), $this->ci->config->item('phpass_hash_portable', 'fx_auth'));
//检查加密密码
if ($hasher->CheckPassword($password, $user->password)) {
// 密码正确
if ($user->banned == 1) {
// 用户是否被锁定
$this->error = array('banned' => $user->ban_reason);
//锁定原因
} else {
//设置session
$this->ci->session->set_userdata(array('user_id' => $user->id, 'user_name' => $user->username, 'status' => $user->activated == 1 ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED));
if ($user->activated == 0) {
// 失败 未活动
$this->error = array('not_activated' => '');
} else {
return true;
}
}
} else {
// 错误密码
$this->error = array('password' => 'auth_incorrect_password');
}
}
}
return FALSE;
}
示例14: checkCredentials
public function checkCredentials($email, $pw)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return false;
}
if (strlen($pw) > 20) {
return false;
}
/*
* Using phpass open-source pw hashing class here.
* It provides its own salt in the has itself,
* and has a function to check if the hash matches.
* We could also store a hash and a salt in the DB
*/
$hasher = new PasswordHash(8, false);
if (!$this->_db) {
$this->_db = DB::getInstance();
}
//get the stored password
$query = 'SELECT password_hash,id,first_name,is_admin FROM users WHERE email = ? LIMIT 1';
$stmt = $this->_db->prepare($query);
$stmt->execute(array($email));
$row = $stmt->fetch();
if ($row['password_hash']) {
if ($hasher->CheckPassword($pw, $row['password_hash'])) {
return array('id' => $row['id'], 'fname' => strip_tags($row['first_name']), 'is_admin' => $row['is_admin']);
}
return false;
}
return false;
}
示例15: checkpwd
function checkpwd($password, $user_login)
{
include "includes/PasswordHash.php";
$hasher = new PasswordHash(8, false);
$stored_hash = "*";
$db = new ezSQL_mysqli(db_user, db_password, db_name, db_host);
if ($db->get_var("SELECT option_value FROM site_options where option_name = 'encrypted_passwords';") == "yes") {
//if encryption is ON
$stored_hash = $db->get_var("SELECT user_password from site_users WHERE user_login = '{$user_login}' OR user_email = '{$user_login}' LIMIT 1;");
$check = $hasher->CheckPassword($password, $stored_hash);
if ($check) {
$return_value = TRUE;
} else {
$return_value = FALSE;
}
//if encryption is OFF
} else {
$num = $db->get_var("select count(user_id) from site_users WHERE (user_login = '{$user_login}' OR user_email = '{$user_login}') AND user_password = BINARY '{$password}' AND user_pending = 0 limit 1;");
if ($num == 1) {
$return_value = TRUE;
} else {
$return_value = FALSE;
}
}
return $return_value;
}