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

首頁 后端開發(fā) php教程 wordpress密碼生成與登錄密碼驗證

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

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

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

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

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

二。密碼生成方式

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

以下為在wordpress中調用密碼生成的代碼

<?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  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) 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 itoa64[($value >> 6) & 0x3f];
			if ($i++ >= $count)
				break;
			if ($i itoa64[($value >> 12) & 0x3f];
			if ($i++ >= $count)
				break;
			$output .= $this->itoa64[($value >> 18) & 0x3f];
		} while ($i 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  30)
			return $output;

		$count = 1 = '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 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) = 16) {
				$output .= $itoa64[$c1];
				break;
			}

			$c2 = ord($input[$i++]);
			$c1 |= $c2 >> 4;
			$output .= $itoa64[$c1];
			$c1 = ($c2 & 0x0f) > 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) get_random_bytes(3);
			$hash =
			    crypt($password, $this->gensalt_extended($random));
			if (strlen($hash) == 20)
				return $hash;
		}

		if (strlen($random) 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的基礎字符串。?

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

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

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

本站聲明
本文內容由網友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅動的應用程序,用于創(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

視覺化網頁開發(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有什么區(qū)別一、外觀GT4:46mm和41mm,材質是玻璃表鏡+不銹鋼機身+高分纖維后殼。GT3pro:46.6mm和42.9mm,材質是藍寶石玻璃表鏡+鈦金屬機身/陶瓷機身+陶瓷后殼二、健康GT4:采用最新的華為Truseen5.5+算法,結果會更加的精準。GT3pro:多了ECG心電圖和血管及安

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

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

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

Count函數(shù)用于計算指定范圍內數(shù)字的個數(shù)。它忽略文本、邏輯值和空值,但會將空單元格計算在內,Count函數(shù)只計算包含實際數(shù)字的單元格數(shù)量。而CountA函數(shù)用于計算指定范圍內非空單元格的個數(shù)。它不僅計算包含實際數(shù)字的單元格,還計算包含文本、邏輯值和公式等非空單元格的數(shù)量。

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

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

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

php提交表單通過后,彈出的對話框怎樣在當前頁彈出php提交表單通過后,彈出的對話框怎樣在當前頁彈出而不是在空白頁彈出?想實現(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各自具有不用的特點和適用場景,如果注重功能的全面性、高性能和時尚外觀,同時愿意承擔較高的價格,那么Watch 4 Pro可能更適合。如果對功能要求不高,更注重電池續(xù)航和價格的合理性,那么GT系列可能更適合。最終的選擇應根據個人需求、預算和喜好來決定,建議在購買前仔細考慮自己的需求,并參考各種產品的評測和比較,以做出更明智的選擇。

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

這篇文章將為大家詳細講解有關PHP將GD圖像輸出到瀏覽器或文件,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。PHP將GD圖像輸出到瀏覽器或文件引言phpGD庫為處理圖像提供了強大的功能,允許您創(chuàng)建、編輯和輸出圖像??梢詫D像輸出到瀏覽器或文件,以進行顯示或進一步處理。輸出到瀏覽器要將圖像輸出到瀏覽器,請使用以下步驟:創(chuàng)建圖像資源:使用imagecreate()函數(shù)創(chuàng)建圖像資源。加載圖像數(shù)據:使用imagepng()、imagejpeg()或imagegif()

See all articles