php實現(xiàn)隨機生成易于記憶的密碼
本文實例講述了php實現(xiàn)隨機生成易于記憶的密碼。分享給大家供大家參考。具體實現(xiàn)方法如下:
這里通過預(yù)定義一些單詞,讓php隨機從這些單詞中選擇進(jìn)行組合生成密碼
function random_readable_pwd($length=10){ // the wordlist from which the password gets generated // (change them as you like) $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,'; $words .= 'green,blue,music,movies,radio,green,turbo,'; $words .= 'mouse,computer,paper,water,fire,storm,chicken,'; $words .= 'boot,freedom,white,nice,player,small,eyes,'; $words .= 'path,kid,box,black,flower,ping,pong,smile,'; $words .= 'coffee,colors,rainbow,plus,king,tv,ring'; // Split by ",": $words = explode(',', $words); if (count($words) == 0){ die('Wordlist is empty!'); } // Add words while password is smaller than the given length $pwd = ''; while (strlen($pwd) < $length){ $r = mt_rand(0, count($words)-1); $pwd .= $words[$r]; } // append a number at the end if length > 2 and // reduce the password size to $length $num = mt_rand(1, 99); if ($length > 2){ $pwd = substr($pwd,0,$length-strlen($num)).$num; } else { $pwd = substr($pwd, 0, $length); } return $pwd; } //使用范例: random_readable_pwd(10) => returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
zend framework配置操作數(shù)據(jù)庫實例分析
zend framework項目建立后,看了下zend framework配置操作數(shù)據(jù)庫,本文將詳細(xì)介紹,需要了解的朋友可以參考下2012-12-12詳解php的魔術(shù)方法__get()和__set()使用介紹
php的魔術(shù)方法__get()和__set()使用介紹,需要的朋友可以參考下2012-09-09PHP跨平臺獲取服務(wù)器IP地址自定義函數(shù)分享
這篇文章主要介紹了PHP跨平臺獲取服務(wù)器IP地址自定義函數(shù)分享,本文函數(shù)會根據(jù)系統(tǒng)類型選擇不同的命令來獲取服務(wù)器的IP地址,需要的朋友可以參考下2014-12-12PHP 使用Echarts生成數(shù)據(jù)統(tǒng)計報表的實現(xiàn)代碼
這篇文章主要介紹了PHP 使用Echarts生成數(shù)據(jù)統(tǒng)計報表的實現(xiàn)代碼,需要的朋友可以參考下2018-01-01PHP面向?qū)ο蟮倪M(jìn)階學(xué)習(xí)(抽像類、接口、final、類常量)
PHP面向?qū)ο蟮倪M(jìn)階學(xué)習(xí),主要包括抽像類、接口、final、類常量的一些資料2012-05-05php編程實現(xiàn)追加內(nèi)容到txt文件中的方法
這篇文章主要介紹了php編程實現(xiàn)追加內(nèi)容到txt文件中的方法,涉及php覆蓋式添加內(nèi)容到txt文件、追加內(nèi)容以及逐行讀取txt文件的相關(guān)操作技巧,需要的朋友可以參考下2017-08-08PHP pthreads v3下的Volatile簡介與使用方法示例
這篇文章主要介紹了PHP pthreads v3下的Volatile簡介與使用方法,結(jié)合實例形式較為詳細(xì)的分析了PHP pthreads v3下Volatile的功能、原理、使用方法及相關(guān)操作注意事項,需要的朋友可以參考下2020-02-02