国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 後端開發(fā) php教程 wordpress密碼產(chǎn)生與登入密碼驗證

wordpress密碼產(chǎn)生與登入密碼驗證

Jul 28, 2016 am 08:28 AM
count gt output this

一。研究wordpress時wordpess的密碼密碼生成與登錄密碼驗證方式很重要

WordPress密碼已成為整合的首要目標(biāo),如何征服整合,就得了解WordPress密碼算法。

WordPress系統(tǒng)的用戶密碼是保存在wp_users數(shù)據(jù)表的user_pass字段,密碼是通過Portable PHP password hashing framework類產(chǎn)生的,密碼的形式是隨機且不可逆,同一個明文的密碼在不同時間,產(chǎn)生的密文也不一樣,相對來說較為安全。

二。密碼生成方式

> 隨機產(chǎn)生一個salt 并將salt和password相加
> 進(jìn)行了count次md5 然后和encode64的hash數(shù)值累加
> 最后得到一個以$P$開頭的密碼,這個密碼每次產(chǎn)生的結(jié)果都不一樣

以下為在wordpress中調(diào)用密碼生成的代碼

<?php
 $password = &#39;abc&#39;;
 global $wp_hasher;
 if ( empty($wp_hasher) ) {
  require_once( &#39;./wp-includes/class-phpass.php&#39;);
  $wp_hasher = new PasswordHash(8, TRUE);
 }
 echo $wp_hasher->HashPassword($password);
?>

三。wordpress密碼生成與登錄驗證

wordpress中位置為\wp-includes\class-phpass.php

以下是wordpress中生成密碼的代碼直接運行可查看密碼的生成以及驗證過程

<?php

class PasswordHash {
	var $itoa64;
	var $iteration_count_log2;
	var $portable_hashes;
	var $random_state;

	function PasswordHash($iteration_count_log2, $portable_hashes)
	{
		$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

		if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
			$iteration_count_log2 = 8;
		$this->iteration_count_log2 = $iteration_count_log2;

		$this->portable_hashes = $portable_hashes;

		$this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compability reasons
	}

	function get_random_bytes($count)
	{
		$output = '';
		if ( @is_readable('/dev/urandom') &&
		    ($fh = @fopen('/dev/urandom', 'rb'))) {
			$output = fread($fh, $count);
			fclose($fh);
		}

		if (strlen($output) < $count) {
			$output = &#39;&#39;;
			for ($i = 0; $i < $count; $i += 16) {
				$this->random_state =
				    md5(microtime() . $this->random_state);
				$output .=
				    pack('H*', md5($this->random_state));
			}
			$output = substr($output, 0, $count);
		}

		return $output;
	}

	function encode64($input, $count)
	{
		$output = '';
		$i = 0;
		do {
			$value = ord($input[$i++]);
			$output .= $this->itoa64[$value & 0x3f];
			if ($i < $count)
				$value |= ord($input[$i]) << 8;
			$output .= $this->itoa64[($value >> 6) & 0x3f];
			if ($i++ >= $count)
				break;
			if ($i < $count)
				$value |= ord($input[$i]) << 16;
			$output .= $this->itoa64[($value >> 12) & 0x3f];
			if ($i++ >= $count)
				break;
			$output .= $this->itoa64[($value >> 18) & 0x3f];
		} while ($i < $count);

		return $output;
	}

	function gensalt_private($input)
	{
		$output = &#39;$PXXXXX;
		$output .= $this->itoa64[min($this->iteration_count_log2 +
			((PHP_VERSION >= '5') ? 5 : 3), 30)];
		$output .= $this->encode64($input, 6);

		return $output;
	}

	function crypt_private($password, $setting)
	{
		$output = '*0';
		if (substr($setting, 0, 2) == $output)
			$output = '*1';

		$id = substr($setting, 0, 3);
		# We use "$P{1}quot;, phpBB3 uses "$H{1}quot; for the same thing
		if ($id != '$PXXXXX && $id != '$HXXXXX)
			return $output;

		$count_log2 = strpos($this->itoa64, $setting[3]);
		if ($count_log2 < 7 || $count_log2 > 30)
			return $output;

		$count = 1 << $count_log2;

		$salt = substr($setting, 4, 8);
		if (strlen($salt) != 8)
			return $output;

		# We&#39;re kind of forced to use MD5 here since it&#39;s the only
		# cryptographic primitive available in all versions of PHP
		# currently in use.  To implement our own low-level crypto
		# in PHP would result in much worse performance and
		# consequently in lower iteration counts and hashes that are
		# quicker to crack (by non-PHP code).
		if (PHP_VERSION >= '5') {
			$hash = md5($salt . $password, TRUE);
			do {
				$hash = md5($hash . $password, TRUE);
			} while (--$count);
		} else {
			$hash = pack('H*', md5($salt . $password));
			do {
				$hash = pack('H*', md5($hash . $password));
			} while (--$count);
		}

		$output = substr($setting, 0, 12);
		$output .= $this->encode64($hash, 16);

		return $output;
	}

	function gensalt_extended($input)
	{
		$count_log2 = min($this->iteration_count_log2 + 8, 24);
		# This should be odd to not reveal weak DES keys, and the
		# maximum valid value is (2**24 - 1) which is odd anyway.
		$count = (1 << $count_log2) - 1;

		$output = &#39;_&#39;;
		$output .= $this->itoa64[$count & 0x3f];
		$output .= $this->itoa64[($count >> 6) & 0x3f];
		$output .= $this->itoa64[($count >> 12) & 0x3f];
		$output .= $this->itoa64[($count >> 18) & 0x3f];

		$output .= $this->encode64($input, 3);

		return $output;
	}

	function gensalt_blowfish($input)
	{
		# This one needs to use a different order of characters and a
		# different encoding scheme from the one in encode64() above.
		# We care because the last character in our encoded string will
		# only represent 2 bits.  While two known implementations of
		# bcrypt will happily accept and correct a salt string which
		# has the 4 unused bits set to non-zero, we do not want to take
		# chances and we also do not want to waste an additional byte
		# of entropy.
		$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

		$output = '$2aXXXXX;
		$output .= chr(ord('0') + $this->iteration_count_log2 / 10);
		$output .= chr(ord('0') + $this->iteration_count_log2 % 10);
		$output .= 'XXXXX;

		$i = 0;
		do {
			$c1 = ord($input[$i++]);
			$output .= $itoa64[$c1 >> 2];
			$c1 = ($c1 & 0x03) << 4;
			if ($i >= 16) {
				$output .= $itoa64[$c1];
				break;
			}

			$c2 = ord($input[$i++]);
			$c1 |= $c2 >> 4;
			$output .= $itoa64[$c1];
			$c1 = ($c2 & 0x0f) << 2;

			$c2 = ord($input[$i++]);
			$c1 |= $c2 >> 6;
			$output .= $itoa64[$c1];
			$output .= $itoa64[$c2 & 0x3f];
		} while (1);

		return $output;
	}

	function HashPassword($password)
	{
		$random = '';

		if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
			$random = $this->get_random_bytes(16);
			$hash =
			    crypt($password, $this->gensalt_blowfish($random));
			if (strlen($hash) == 60)
				return $hash;
		}

		if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
			if (strlen($random) < 3)
				$random = $this->get_random_bytes(3);
			$hash =
			    crypt($password, $this->gensalt_extended($random));
			if (strlen($hash) == 20)
				return $hash;
		}

		if (strlen($random) < 6)
			$random = $this->get_random_bytes(6);
		$hash =
		    $this->crypt_private($password,
		    $this->gensalt_private($random));
		if (strlen($hash) == 34)
			return $hash;

		# Returning '*' on error is safe here, but would _not_ be safe
		# in a crypt(3)-like function used _both_ for generating new
		# hashes and for validating passwords against existing hashes.
		return '*';
	}

	function CheckPassword($password, $stored_hash)
	{
		$hash = $this->crypt_private($password, $stored_hash);
		if ($hash[0] == '*')
			$hash = crypt($password, $stored_hash);

		return $hash == $stored_hash;
	}
}

//原始密碼
$passwordValue = "123456";

//生成密碼
$wp_hasher = new PasswordHash(8, TRUE);
$sigPassword = $wp_hasher->HashPassword($passwordValue);
echo "生成的密碼為:".$sigPassword;
echo "\n";

//驗證密碼
$data = $wp_hasher->CheckPassword($passwordValue,$sigPassword);
if($data){
    echo '密碼正確';
}else{
	echo '密碼錯誤';
}

?>
此為一個wordpres密碼生成與登錄驗證實例,其中HashPassword為生成密碼,CheckPassword為驗證密碼

itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 為以上提到的生成salt的基礎(chǔ)字符串。?

備注:由于csdn代碼顯示插件對特殊字符的限制。 請將以上代碼中 XXXXX替換為?$' ?注意有單引號,代碼中一共有5處

原博客鏈接:http://blog.csdn.net/chengfei112233/article/details/6939144/

以上就介紹了 wordpress密碼生成與登錄密碼驗證,包括了方面的內(nèi)容,希望對PHP教程有興趣的朋友有所幫助。

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

華為GT3 Pro和GT4的差異是什麼? 華為GT3 Pro和GT4的差異是什麼? Dec 29, 2023 pm 02:27 PM

許多用戶在選擇智慧型手錶的時候都會選擇的華為的品牌,其中華為GT3pro和GT4都是非常熱門的選擇,不少用戶都很好奇華為GT3pro和GT4有什麼區(qū)別,下面就給大家介紹一下二者。華為GT3pro和GT4有什麼差別一、外觀GT4:46mm和41mm,材質(zhì)是玻璃鏡板+不鏽鋼機身+高分纖維後殼。 GT3pro:46.6mm和42.9mm,材質(zhì)是藍(lán)寶石玻璃鏡+鈦金屬機身/陶瓷機身+陶瓷後殼二、健康GT4:採用最新的華為Truseen5.5+演算法,結(jié)果會更加的精準(zhǔn)。 GT3pro:多了ECG心電圖和血管及安

修復(fù):截圖工具在 Windows 11 中不起作用 修復(fù):截圖工具在 Windows 11 中不起作用 Aug 24, 2023 am 09:48 AM

為什麼截圖工具在Windows11上不起作用了解問題的根本原因有助於找到正確的解決方案。以下是截圖工具可能無法正常工作的主要原因:對焦助手已開啟:這可以防止截圖工具開啟。應(yīng)用程式損壞:如果截圖工具在啟動時崩潰,則可能已損壞。過時的圖形驅(qū)動程式:不相容的驅(qū)動程式可能會幹?jǐn)_截圖工具。來自其他應(yīng)用程式的干擾:其他正在運行的應(yīng)用程式可能與截圖工具衝突。憑證已過期:升級過程中的錯誤可能會導(dǎo)致此issu簡單的解決方案這些適合大多數(shù)用戶,不需要任何特殊的技術(shù)知識。 1.更新視窗與Microsoft應(yīng)用程式商店應(yīng)用程

counta和count的區(qū)別 counta和count的區(qū)別 Nov 20, 2023 am 10:01 AM

Count函數(shù)用於計算指定範(fàn)圍內(nèi)數(shù)字的個數(shù)。它忽略文字、邏輯值和空值,但會將空白儲存格計算在內(nèi),Count函數(shù)只計算包含實際數(shù)字的儲存格數(shù)量。而CountA函數(shù)用於計算指定範(fàn)圍內(nèi)非空單元格的個數(shù)。它不僅計算包含實際數(shù)字的儲存格,還計算包含文字、邏輯值和公式等非空白儲存格的數(shù)量。

如何修復(fù)無法連線到iPhone上的App Store錯誤 如何修復(fù)無法連線到iPhone上的App Store錯誤 Jul 29, 2023 am 08:22 AM

第1部分:初始故障排除步驟檢查蘋果的系統(tǒng)狀態(tài):在深入研究複雜的解決方案之前,讓我們先從基礎(chǔ)知識開始。問題可能不在於您的設(shè)備;蘋果的伺服器可能會關(guān)閉。造訪Apple的系統(tǒng)狀態(tài)頁面,查看AppStore是否正常運作。如果有問題,您所能做的就是等待Apple修復(fù)它。檢查您的網(wǎng)路連接:確保您擁有穩(wěn)定的網(wǎng)路連接,因為「無法連接到AppStore」問題有時可歸因於連接不良。嘗試在Wi-Fi和行動數(shù)據(jù)之間切換或重置網(wǎng)路設(shè)定(「常規(guī)」>「重置」>「重置網(wǎng)路設(shè)定」>設(shè)定)。更新您的iOS版本:

php提交表單通過后,彈出的對話框怎樣在當(dāng)前頁彈出,該如何解決 php提交表單通過后,彈出的對話框怎樣在當(dāng)前頁彈出,該如何解決 Jun 13, 2016 am 10:23 AM

php提交表單通過后,彈出的對話框怎樣在當(dāng)前頁彈出php提交表單通過后,彈出的對話框怎樣在當(dāng)前頁彈出而不是在空白頁彈出?想實現(xiàn)這樣的效果:而不是空白頁彈出:------解決方案--------------------如果你的驗證用PHP在后端,那么就用Ajax;僅供參考:HTML code

聊聊Vue2為什麼能透過this存取各種選項中屬性 聊聊Vue2為什麼能透過this存取各種選項中屬性 Dec 08, 2022 pm 08:22 PM

這篇文章帶大家解讀vue原始碼,來介紹一下Vue2中為什麼可以使用 this 存取各種選項中的屬性,希望對大家有幫助!

watch4pro好還是gt好 watch4pro好還是gt好 Sep 26, 2023 pm 02:45 PM

watch4pro和gt各自具有不使用的特點和適用場景,如果注重功能的全面性、高性能和時尚外觀,同時願意承擔(dān)較高的價格,那麼Watch 4 Pro可能更適合。如果對功能要求不高,更注重電池續(xù)航力和價格的合理性,那麼GT系列可能更適合。最終的選擇應(yīng)根據(jù)個人需求、預(yù)算和喜好來決定,建議在購買前仔細(xì)考慮自己的需求,並參考各種產(chǎn)品的評測和比較,以做出更明智的選擇。

PHP將 GD 映像輸出到瀏覽器或文件 PHP將 GD 映像輸出到瀏覽器或文件 Mar 21, 2024 am 10:41 AM

這篇文章將為大家詳細(xì)講解有關(guān)PHP將GD圖像輸出到瀏覽器或文件,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章後可以有所收穫。 PHP將GD影像輸出到瀏覽器或檔案引言phpGD函式庫為處理影像提供了強大的功能,可讓您建立、編輯和輸出映像。可以將影像輸出到瀏覽器或文件,以進(jìn)行顯示或進(jìn)一步處理。輸出到瀏覽器要將映像輸出到瀏覽器,請使用下列步驟:建立映像資源:使用imagecreate()函數(shù)建立映像資源。載入圖片資料:使用imagepng()、imagejpeg()或imagegif()

See all articles