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


PHP PasswordHash::get_random_bytes方法代码示例

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


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

示例1: _pantheon_session_open

/**
 * Session handler assigned by session_set_save_handler().
 *
 * This function is used to handle any initialization, such as file paths or
 * database connections, that is needed before accessing session data. The plugin
 * does not need to initialize anything in this function.
 *
 * This function should not be called directly.
 *
 * @return true
 */
function _pantheon_session_open() {
	// We use !empty() in the following check to ensure that blank session IDs are not valid.
	if ( ! empty( $_COOKIE[ session_name() ] ) || ( is_ssl() && ! empty( $_COOKIE[ substr(session_name(), 1) ] ) ) ) {
		// If a session cookie exists, initialize the session. Otherwise the
		// session is only started on demand in _pantheon_session_write(), making
		// anonymous users not use a session cookie unless something is stored in
		// $_SESSION. This allows HTTP proxies to cache anonymous pageviews.
		if ( get_current_user_id() || ! empty( $_SESSION ) ) {
			nocache_headers();
		}
	} else {
		// Set a session identifier for this request. This is necessary because
		// we lazily start sessions at the end of this request
		require_once( ABSPATH . 'wp-includes/class-phpass.php');
		$hasher = new PasswordHash( 8, false );
		session_id( md5( $hasher->get_random_bytes( 32 ) ) );
		if ( is_ssl() ) {
			$insecure_session_name = substr( session_name(), 1 );
			$insecure_session_id = md5( $hasher->get_random_bytes( 32 ) );
			//set custom expire time during cookie session creation
			$lifetime = (int) apply_filters( 'pantheon_session_expiration', 0 );
			setcookie( $insecure_session_name, $insecure_session_id, $_SERVER['REQUEST_TIME'] + $lifetime);
		}
	}
	return true;
}
开发者ID:jknowles94,项目名称:Work-examples,代码行数:37,代码来源:callbacks.php

示例2: generate_key

 public static function generate_key($bitsize = self::DEFAULT_KEY_BIT_SIZE)
 {
     global $wp_hasher;
     if ($bitsize < 8 || $bitsize % 8 !== 0) {
         // @TODO: handle this
         wp_die(-1);
     }
     if (empty($wp_hasher)) {
         require_once ABSPATH . WPINC . '/class-phpass.php';
         $wp_hasher = new PasswordHash(8, true);
     }
     return base64_encode($wp_hasher->get_random_bytes($bitsize / 8));
 }
开发者ID:voldemortensen,项目名称:two-factor,代码行数:13,代码来源:class.two-factor-totp.php

示例3: generate_customer_id

 /**
  * Generate a unique customer ID for guests, or return user ID if logged in.
  *
  * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.
  *
  * @return int|string
  */
 public function generate_customer_id()
 {
     if (is_user_logged_in()) {
         return get_current_user_id();
     } else {
         require_once ABSPATH . 'wp-includes/class-phpass.php';
         $hasher = new PasswordHash(8, false);
         return md5($hasher->get_random_bytes(32));
     }
 }
开发者ID:jgcopple,项目名称:drgaryschwantz,代码行数:17,代码来源:class-wc-session-handler.php

示例4: generate_id

 /**
  * Generate a cryptographically strong unique ID for the session token.
  *
  * @return string
  */
 protected function generate_id()
 {
     require_once ABSPATH . 'wp-includes/class-phpass.php';
     $hasher = new PasswordHash(8, false);
     return md5($hasher->get_random_bytes(32));
 }
开发者ID:RcArtSolutions,项目名称:wp-entry-list,代码行数:11,代码来源:WP_Session.class.php

示例5: tep_create_random_value

function tep_create_random_value($length, $type = 'mixed')
{
    if ($type != 'mixed' && $type != 'chars' && $type != 'digits') {
        $type = 'mixed';
    }
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $digits = '0123456789';
    $base = '';
    if ($type == 'mixed' || $type == 'chars') {
        $base .= $chars;
    }
    if ($type == 'mixed' || $type == 'digits') {
        $base .= $digits;
    }
    $value = '';
    if (!class_exists('PasswordHash')) {
        include 'includes/classes/passwordhash.php';
    }
    $hasher = new PasswordHash(10, true);
    do {
        $random = base64_encode($hasher->get_random_bytes($length));
        for ($i = 0, $n = strlen($random); $i < $n; $i++) {
            $char = substr($random, $i, 1);
            if (strpos($base, $char) !== false) {
                $value .= $char;
            }
        }
    } while (strlen($value) < $length);
    if (strlen($value) > $length) {
        $value = substr($value, 0, $length);
    }
    return $value;
}
开发者ID:katapofatico,项目名称:Responsive-osCommerce,代码行数:33,代码来源:general.php

示例6: _set_session_id

 /**
  * Generate a session id
  *
  * @return string session id
  */
 protected function _set_session_id()
 {
     require_once ABSPATH . 'wp-includes/class-phpass.php';
     $hash = new PasswordHash(8, false);
     self::$session_id = md5($hash->get_random_bytes(32));
     return self::$session_id;
 }
开发者ID:sabdev1,项目名称:ljcdevsab,代码行数:12,代码来源:dls-session.php

示例7: encrypt

 private function encrypt($password, $master_password = false)
 {
     // decrypt the master password
     if ($master_password === false) {
         $master_password = $this->account->decrypt_password();
     }
     // generate a random salt
     require_once "PasswordHash.php";
     $hasher = new PasswordHash(8, false);
     $salt = $hasher->get_random_bytes(100);
     // hash the master password
     $master_password = $this->keygen_s2k($master_password, $salt, 32);
     // encrypt the password with the hashed master password
     $crypt = new PHP_Crypt($master_password, PHP_Crypt::CIPHER_AES_256, PHP_Crypt::MODE_CTR);
     $iv = $crypt->createIV();
     $encrypted_password = $crypt->encrypt($password);
     // return all important variables
     return array("iv" => $iv, "encrypted_password" => $encrypted_password, "salt" => $salt);
 }
开发者ID:NextPass,项目名称:NextPass,代码行数:19,代码来源:Password.php

示例8: createRandomValue

 function createRandomValue($length, $type = 'mixed')
 {
     if ($type != 'mixed' && $type != 'chars' && $type != 'digits') {
         $type = 'mixed';
     }
     $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $digits = '0123456789';
     $base = '';
     if ($type == 'mixed' || $type == 'chars') {
         $base .= $chars;
     }
     if ($type == 'mixed' || $type == 'digits') {
         $base .= $digits;
     }
     $value = '';
     if (!class_exists('PasswordHash') && file_exists(DIR_FS_CATALOG . 'includes/classes/passwordhash.php')) {
         include DIR_FS_CATALOG . 'includes/classes/passwordhash.php';
         $hasher = new PasswordHash(10, true);
         do {
             $random = base64_encode($hasher->get_random_bytes($length));
             for ($i = 0, $n = strlen($random); $i < $n; $i++) {
                 $char = substr($random, $i, 1);
                 if (strpos($base, $char) !== false) {
                     $value .= $char;
                 }
             }
         } while (strlen($value) < $length);
         if (strlen($value) > $length) {
             $value = substr($value, 0, $length);
         }
         return $value;
     }
     // fallback for v2.3.1
     while (strlen($value) < $length) {
         if ($type == 'digits') {
             $char = tep_rand(0, 9);
         } else {
             $char = chr(tep_rand(0, 255));
         }
         if ($type == 'mixed') {
             if (preg_match('/^[a-z0-9]$/i', $char)) {
                 $value .= $char;
             }
         } elseif ($type == 'chars') {
             if (preg_match('/^[a-z]$/i', $char)) {
                 $value .= $char;
             }
         } elseif ($type == 'digits') {
             if (preg_match('/^[0-9]$/i', $char)) {
                 $value .= $char;
             }
         }
     }
     return $value;
 }
开发者ID:katapofatico,项目名称:Responsive-osCommerce,代码行数:55,代码来源:OSCOM_PayPal.php

示例9: tep_generate_password

function tep_generate_password($length)
{
    if (!class_exists('PasswordHash')) {
        include DIR_WS_CLASSES . 'passwordhash.php';
    }
    $hasher = new PasswordHash(10, true);
    return substr(base64_encode($hasher->get_random_bytes($length * 2)), 0, $length);
}
开发者ID:randomecho,项目名称:oscommerce2,代码行数:8,代码来源:password_funcs.php


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