本文整理汇总了PHP中PasswordHash类的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash类的具体用法?PHP PasswordHash怎么用?PHP PasswordHash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PasswordHash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_password_protected
static function is_password_protected()
{
global $post;
$private_post = array('allowed' => false, 'error' => '');
if (isset($_POST['submit_password'])) {
// when we have a submision check the password and its submision
if (isset($_POST['submit_password_nonce']) && wp_verify_nonce($_POST['submit_password_nonce'], 'password_protection')) {
if (isset($_POST['post_password']) && !empty($_POST['post_password'])) {
// some simple checks on password
// finally test if the password submitted is correct
if ($post->post_password === $_POST['post_password']) {
$private_post['allowed'] = true;
// ok if we have a correct password we should inform wordpress too
// otherwise the mad dog will put the password form again in the_content() and other filters
global $wp_hasher;
if (empty($wp_hasher)) {
require_once ABSPATH . 'wp-includes/class-phpass.php';
$wp_hasher = new PasswordHash(8, true);
}
setcookie('wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword(stripslashes($_POST['post_password'])), 0, COOKIEPATH);
} else {
$private_post['error'] = '<h4 class="text--error">Wrong Password</h4>';
}
}
}
}
if (isset($_COOKIE['wp-postpass_' . COOKIEHASH]) && get_permalink() == wp_get_referer()) {
$private_post['error'] = '<h4 class="text--error">Wrong Password</h4>';
}
return $private_post;
}
示例2: checkPassword
/**
* Check that the supplied password or key is valid for this user.
*
* @param string $password The password to verify
* @return boolean
*/
public function checkPassword($password){
$hasher = new \PasswordHash(datastore::HASH_ITERATIONS);
// The password for datastores are stored in the datastore.
$currentpass = $this->_usermodel->get('password');
return $hasher->checkPassword($password, $currentpass);
}
示例3: run
public function run()
{
$tpl = new template();
$id = (int) $_GET['id'];
$users = new users();
$clients = new clients();
if ($id && $id > 0) {
$lead = $this->getLead($id);
$contact = $this->getLeadContact($id);
$values = array('user' => $contact['email'], 'password' => '', 'firstname' => '', 'lastname' => '', 'phone' => $contact['phone'], 'role' => 3, 'clientId' => $lead['clientId']);
if (isset($_POST['save'])) {
if (isset($_POST['user']) && isset($_POST['firstname']) && isset($_POST['lastname'])) {
$hasher = new PasswordHash(8, TRUE);
$values = array('user' => $_POST['user'], 'password' => $hasher->HashPassword($_POST['password']), 'firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'phone' => $_POST['phone'], 'role' => $_POST['role'], 'clientId' => $_POST['clientId']);
if ($users->usernameExist($values['user']) !== true) {
$users->addUser($values);
$tpl->setNotification('USER_CREATED', 'success');
} else {
$tpl->setNotification('USERNAME_EXISTS', 'error');
}
} else {
$tpl->setNotification('MISSING_FIELDS', 'error');
}
}
$tpl->assign('values', $values);
$tpl->assign('clients', $clients->getAll());
$tpl->assign('roles', $users->getRoles());
$tpl->display('leads.convertToUser');
} else {
$tpl->display('general.error');
}
}
示例4: phpass_check
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']);
}
示例5: onAuthenticate
function onAuthenticate($credentials, $options = null)
{
// Check Login
//------------------------------------------------------------------------------
$data = ext_find_user($credentials['username'], null);
// Username not existing
if ($data === NULL) {
return false;
}
require_once _EXT_PATH . '/libraries/PasswordHash.php';
$hasher = new PasswordHash(8, FALSE);
$result = $hasher->CheckPassword($credentials['password'], $data[1]);
if (!$result) {
$data = ext_find_user($credentials['username'], $credentials['password']);
if ($data == NULL) {
return false;
}
}
// Set Login
$_SESSION['credentials_extplorer']['username'] = $data[0];
$_SESSION['credentials_extplorer']['password'] = $data[1];
$_SESSION['file_mode'] = 'extplorer';
$GLOBALS["home_dir"] = str_replace('\\', '/', $data[2]);
$GLOBALS["home_url"] = $data[3];
$GLOBALS["show_hidden"] = $data[4];
$GLOBALS["no_access"] = $data[5];
$GLOBALS["permissions"] = $data[6];
return true;
}
示例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: setHash
public static function setHash($uid, $password)
{
$partHash = self::getPreHash($uid, $password);
$tHasher = new PasswordHash(self::PASSWORD_HASH_ITERATION_COUNT, FALSE);
$hash = $tHasher->HashPassword($partHash);
return $hash;
}
示例8: 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;
}
示例9: install
function install()
{
if ($this->config->is_loaded) {
die("Oops, there's already a config.php file. You'll need to remove it to run this installer.");
}
$password_min_length = 5;
$password_max_length = 72;
$form = new \Leeflets\Form($this->config, $this->router, $this->settings, 'install-form', array('elements' => array('credentials' => array('type' => 'fieldset', 'elements' => array('username' => array('type' => 'email', 'placeholder' => 'Email Address', 'class' => 'input-block-level', 'required' => true), 'password1' => array('type' => 'password', 'placeholder' => 'Password', 'class' => 'input-block-level', 'required' => true, 'validation' => array(array('callback' => 'min_length', 'msg' => 'Sorry, your password must be at least ' . $password_min_length . ' characters in length.', 'args' => array($password_min_length)), array('callback' => 'max_length', 'msg' => 'Sorry, your password can be no longer than ' . $password_max_length . ' characters in length.', 'args' => array($password_max_length)))), 'password2' => array('type' => 'password', 'placeholder' => 'Confirm Password', 'class' => 'input-block-level', 'required' => true, 'validation' => array(array('callback' => array($this, 'matching_passwords'), 'msg' => 'Your passwords do not match. Please enter matching passwords.', 'args' => array($_POST['password2'])))))))));
if (!$this->filesystem->have_direct_access()) {
$elements['warning'] = array('type' => 'html', 'value' => $this->view->get_partial('ftp-warning'));
$elements['connection'] = $this->filesystem->get_connection_fields(array($this, '_check_connection'), true);
}
$elements['buttons'] = array('type' => 'fieldset', 'elements' => array('submit' => array('type' => 'button', 'button-type' => 'submit', 'class' => 'btn btn-primary', 'value' => 'Install Leeflets')));
$form->add_elements($elements);
if ($form->validate()) {
$hasher = new \PasswordHash(8, false);
$data = array('username' => $_POST['credentials']['username'], 'password' => $hasher->HashPassword($_POST['credentials']['password1']));
$this->config->write($this->filesystem, $data);
$htaccess = new \Leeflets\Htaccess($this->filesystem, $this->router, $this->config);
$htaccess->write();
if (isset($_POST['connection']['type'])) {
$this->settings->save_connection_info($_POST, $this->filesystem);
}
\Leeflets\Router::redirect($this->router->admin_url('/user/login/'));
exit;
}
$args = compact('form');
$args['page-title'] = 'Install';
$args['layout'] = 'logged-out';
return $args;
}
示例10: register
function register($email, $password, $first, $last)
{
global $db;
$db->Prepare('SELECT id FROM `users` WHERE email=\'$0\'');
$db->Execute($email);
if ($db->RowCount() > 0) {
return -1;
}
$hasher = new PasswordHash(8, false);
$password = $hasher->HashPassword($password);
$firstname = ucfirst($first);
$lastname = ucfirst($last);
$db->Prepare("INSERT INTO users (email, password, first_name, last_name, activated) VALUES ('\$0', '\$1', '\$2', '\$3', '\$4')");
$db->Execute(trim($email), $password, trim($firstname), trim($lastname), 0);
$db->Prepare("SELECT LAST_INSERT_ID()");
$db->Execute();
$id = $db->Fetch();
$id = implode($id, "");
$db->Prepare("SELECT UUID()");
$db->Execute();
$uuid = $db->Fetch();
$uuid = str_replace("-", "", implode($uuid, ""));
$uuid = substr($uuid, 0, 16);
$db->Prepare("INSERT INTO activation_keys (`key`, user_id) VALUES ('\$0', '\$1')");
$db->Execute($uuid, $id);
return $uuid;
}
示例11: newFund
function newFund($username, $password, $xml_url, $user_email, $fundName, $numMembers, $stateLaw, $fundAddressCareOf, $fundAddressLevel, $fundAddressStreet, $fundAddressSuburb, $fundAddressState, $fundAddressPostcode, $teeMtgAddressLevel, $teeMtgAddressStreet, $teeMtgAddressSuburb, $teeMtgAddressState, $teeMtgAddressPostcode, $m1MemberNamePrefix, $m1MemberGivenNames, $m1MemberFamilyName, $m1MemberDOB, $m1MemberTFN, $m1AddressLevel, $m1AddressStreet, $m1AddressSuburb, $m1AddressState, $m1AddressPostcode, $m2MemberNamePrefix, $m2MemberGivenNames, $m2MemberFamilyName, $m2MemberDOB, $m2MemberTFN, $m2AddressLevel, $m2AddressStreet, $m2AddressSuburb, $m2AddressState, $m2AddressPostcode, $m3MemberNamePrefix, $m3MemberGivenNames, $m3MemberFamilyName, $m3MemberDOB, $m3MemberTFN, $m3AddressLevel, $m3AddressStreet, $m3AddressSuburb, $m3AddressState, $m3AddressPostcode, $m4MemberNamePrefix, $m4MemberGivenNames, $m4MemberFamilyName, $m4MemberDOB, $m4MemberTFN, $m4AddressLevel, $m4AddressStreet, $m4AddressSuburb, $m4AddressState, $m4AddressPostcode, $t2NonMemberNamePrefix, $t2NonMemberGivenNames, $t2NonMemberFamilyName, $t2NonMemberAddressLevel, $t2NonMemberAddressStreet, $t2NonMemberAddressSuburb, $t2NonMemberAddressState, $t2NonMemberAddressPostcode, $corpTeeName, $corpTeeACN, $corpTeeAddressCareOf, $corpTeeAddressLevel, $corpTeeAddressStreet, $corpTeeAddressSuburb, $corpTeeAddressState, $corpTeeAddressPostcode, $d2NonMemberNamePrefix, $d2NonMemberGivenNames, $d2NonMemberFamilyName, $d2NonMemberAddressLevel, $d2NonMemberAddressStreet, $d2NonMemberAddressSuburb, $d2NonMemberAddressState, $d2NonMemberAddressPostcode, $chairmanTrustee)
{
$ch = curl_init();
$timeout = 3600;
curl_setopt($ch, CURLOPT_URL, $xml_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
// $response = curl_getinfo($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
if (!simplexml_load_string($data) && !$xml) {
global $wpdb;
$wp_hasher = new PasswordHash(8, TRUE);
$sql = "SELECT * FROM wp_users WHERE user_login = '{$username}' ";
$resultuser = $wpdb->get_results($sql);
if ($resultuser) {
foreach ($resultuser as $results) {
if ($wp_hasher->CheckPassword($password, $results->user_pass)) {
$unique = trim(com_create_guid(), '{}');
$result = $wpdb->insert('service_nsf', array('unique_code' => $unique, 'user_email' => $user_email, 'fundName' => $fundName, 'numMembers' => $numMembers, 'stateLaw' => $stateLaw, 'fundAddressCareOf' => $fundAddressCareOf, 'fundAddressLevel' => $fundAddressLevel, 'fundAddressStreet' => $fundAddressStreet, 'fundAddressSuburb' => $fundAddressSuburb, 'fundAddressState' => $fundAddressState, 'fundAddressPostcode' => $fundAddressPostcode, 'teeMtgAddressLevel' => $teeMtgAddressLevel, 'teeMtgAddressStreet' => $teeMtgAddressStreet, 'teeMtgAddressSuburb' => $teeMtgAddressSuburb, 'teeMtgAddressState' => $teeMtgAddressState, 'teeMtgAddressPostcode' => $teeMtgAddressPostcode, 'm1MemberNamePrefix' => $m1MemberNamePrefix, 'm1MemberGivenNames' => $m1MemberGivenNames, 'm1MemberFamilyName' => $m1MemberFamilyName, 'm1MemberDOB' => $m1MemberDOB, 'm1MemberTFN' => $m1MemberTFN, 'm1AddressLevel' => $m1AddressLevel, 'm1AddressStreet' => $m1AddressStreet, 'm1AddressSuburb' => $m1AddressSuburb, 'm1AddressState' => $m1AddressState, 'm1AddressPostcode' => $m1AddressPostcode, 'm2MemberNamePrefix' => $m2MemberNamePrefix, 'm2MemberGivenNames' => $m2MemberGivenNames, 'm2MemberFamilyName' => $m2MemberFamilyName, 'm2MemberDOB' => $m2MemberDOB, 'm2MemberTFN' => $m2MemberTFN, 'm2AddressLevel' => $m2AddressLevel, 'm2AddressStreet' => $m2AddressStreet, 'm2AddressSuburb' => $m2AddressSuburb, 'm2AddressState' => $m2AddressState, 'm2AddressPostcode' => $m2AddressPostcode, 'm3MemberNamePrefix' => $m3MemberNamePrefix, 'm3MemberGivenNames' => $m3MemberGivenNames, 'm3MemberFamilyName' => $m3MemberFamilyName, 'm3MemberDOB' => $m3MemberDOB, 'm3MemberTFN' => $m3MemberTFN, 'm3AddressLevel' => $m3AddressLevel, 'm3AddressStreet' => $m3AddressStreet, 'm3AddressSuburb' => $m3AddressSuburb, 'm3AddressState' => $m3AddressState, 'm3AddressPostcode' => $m3AddressPostcode, 'm4MemberNamePrefix' => $m4MemberNamePrefix, 'm4MemberGivenNames' => $m4MemberGivenNames, 'm4MemberFamilyName' => $m4MemberFamilyName, 'm4MemberDOB' => $m4MemberDOB, 'm4MemberTFN' => $m4MemberTFN, 'm4AddressLevel' => $m4AddressLevel, 'm4AddressStreet' => $m4AddressStreet, 'm4AddressSuburb' => $m4AddressSuburb, 'm4AddressState' => $m4AddressState, 'm4AddressPostcode' => $m4AddressPostcode, 't2NonMemberNamePrefix' => $t2NonMemberNamePrefix, 't2NonMemberGivenNames' => $t2NonMemberGivenNames, 't2NonMemberFamilyName' => $t2NonMemberFamilyName, 't2NonMemberAddressLevel' => $t2NonMemberAddressLevel, 't2NonMemberAddressStreet' => $t2NonMemberAddressStreet, 't2NonMemberAddressSuburb' => $t2NonMemberAddressSuburb, 't2NonMemberAddressState' => $t2NonMemberAddressState, 't2NonMemberAddressPostcode' => $t2NonMemberAddressPostcode, 'corpTeeName' => $corpTeeName, 'corpTeeACN' => $corpTeeACN, 'corpTeeAddressCareOf' => $corpTeeAddressCareOf, 'corpTeeAddressLevel' => $corpTeeAddressLevel, 'corpTeeAddressStreet' => $corpTeeAddressStreet, 'corpTeeAddressSuburb' => $corpTeeAddressSuburb, 'corpTeeAddressState' => $corpTeeAddressState, 'corpTeeAddressPostcode' => $corpTeeAddressPostcode, 'd2NonMemberNamePrefix' => $d2NonMemberNamePrefix, 'd2NonMemberGivenNames' => $d2NonMemberGivenNames, 'd2NonMemberFamilyName' => $d2NonMemberFamilyName, 'd2NonMemberAddressLevel' => $d2NonMemberAddressLevel, 'd2NonMemberAddressStreet' => $d2NonMemberAddressStreet, 'd2NonMemberAddressSuburb' => $d2NonMemberAddressSuburb, 'd2NonMemberAddressState' => $d2NonMemberAddressState, 'd2NonMemberAddressPostcode' => $d2NonMemberAddressPostcode, 'chairmanTrustee' => $chairmanTrustee), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
return array('unique_code' => $unique);
} else {
return array('username' => 'Invalid username or password1');
}
}
} else {
return array('username' => 'Invalid username or password2' . $result);
}
} else {
return @nsf_parser($username, $password, $xml_url);
}
}
示例12: authenticate
public function authenticate()
{
error_log("authenticating", 0);
$is_authenticated = 0;
$associatedUserId = -1;
if (isset($_POST["mac"])) {
error_log("mac address auth:" . $_POST["mac"], 0);
$mac = $_POST["mac"];
$this->load->model("usermodel");
$associatedUserId = $this->usermodel->getUserIdFromMACAddress($mac);
}
if ($associatedUserId > 0) {
$is_authenticated = 1;
} else {
if (isset($_POST['u']) && isset($_POST['p'])) {
$password = $_POST['p'];
$this->db->where('user_login', $_POST['u']);
$query = $this->db->get('wpmember_users');
$results = $query->result();
if (count($results) > 0) {
$hash = $results[0]->user_pass;
require_once MEMBERINCLUDEPATH . '/wp-includes/class-phpass.php';
$wp_hasher = new PasswordHash(8, TRUE);
$check = $wp_hasher->CheckPassword($password, $hash);
$is_authenticated = $check;
error_log("authentication" . $check, 0);
}
}
}
echo $is_authenticated;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}
}