mt_rand ( int $min , int $max )函数用于生成随机整数,其中$min–$max为ascii码的范围,这里取33-126,可以根据需要调整范围,如ascii码表中97–122位对应a–z的英文字母,具体可参考ascii码表;chr ( int $ascii )函数用于将对应整数$ascii转换成对应的字符,代码如下:
- function create_password($pw_length = 8)
- {
- $randpwd = '';
- for ($i = 0; $i < $pw_length; $i++)
- {
- $randpwd .= chr(mt_rand(33, 126));
- }
- return $randpwd;
- }
- // 调用该函数,传递长度参数$pw_length = 6
- echo create_password(6);
方法二:
1、预置一个的字符串$chars,包括a–z、a–z、0–9以及一些特殊字符;
2、在$chars字符串中随机取一个字符;
3、重复第二步n次,可得长度为n的密码,代码如下:
- function generate_password( $length = 8 ) {
- // 密码字符集,可任意添加你需要的字符
- $chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
- $password = '';
- for ( $i = 0; $i < $length; $i++ )
- {
- // 这里提供两种字符获取方式
- // 第一种是使用 substr 截取$chars中的任意一位字符;
- // 第二种是取字符数组 $chars 的任意元素
- // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1);
- $password .= $chars[ mt_rand(0, strlen($chars) – 1) ];
- }
- return $password;
- }
方法三:
1、预置一个的字符数组$chars,包括a–z、a–z、0–9以及一些特殊字符;
2、通过array_rand()从数组$chars中随机选出$length个元素;
3、根据已获取的键名数组$keys,从数组$chars取出字符拼接字符串。
该方法的缺点是相同的字符不会重复取,代码如下:
- function make_password( $length = 8 )
- {
- // 密码字符集,可任意添加你需要的字符
- $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
- 'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's',
- 't', 'u', 'v', 'w', 'x', 'y','z', 'a', 'b', 'c', 'd',
- 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l','m', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y','z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!',
- '@','#', '$', '%', '^', '&', '*', '(', ')', '-', '_',
- '[', ']', '{', '}', '<', '>', '~', '`', '+', '=', ',',
- '.', ';', ':', '/', '?', '|');
- // 在 $chars 中随机取 $length 个数组元素键名
- $keys = ($chars, $length);
- $password = '';
- for($i = 0; $i < $length; $i++)
- {
- // 将 $length 个数组元素连接成字符串
- $password .= $chars[$keys[$i]];
- }
- return $password;
- }
时间效率对比:我们使用以下php代码,计算上面的3个随机密码生成函数生成6位密码的运行时间,进而对他们的时间效率进行一个简单的对比,代码如下:
- function getmicrotime()
- {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- // 记录开始时间
- $time_start = getmicrotime();
- // 这里放要执行的php代码,如:
- // echo create_password(6);
- // 记录结束时间
- $time_end = getmicrotime();
- $time = $time_end – $time_start;
- // 输出运行总时间
- echo "执行时间 $time seconds";
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php中生成随机密码几种方法
波比源码 » php中生成随机密码几种方法
levaquin 500mg us order levaquin 250mg
order fildena 50mg generic bimatoprost online order methocarbamol order online
suhagra 50mg without prescription purchase aurogra pill order estrace pill
lamictal medication order lamotrigine sale purchase retin sale
brand indomethacin 75mg suprax usa generic amoxicillin 500mg
clozaril pill buy combivent 100mcg online buy dexamethasone sale
metoprolol 100mg pills buy lopressor 100mg online order vardenafil 20mg pills
cialis 20mg price buy tadalafil 40mg pills brand viagra
purchase aristocort for sale order loratadine online cheap clarinex 5mg cheap
orlistat 120mg brand acyclovir ca zovirax 800mg ca
zyloprim 100mg pill allopurinol 100mg oral oral zetia
cialis pills 20mg buy cialis 10mg generic ciprofloxacin online buy
buy fluconazole 200mg online brand fluconazole cheap sildenafil
tadalafil 5mg tablet sildenafil 50mg brand order viagra online
sildenafil overnight delivery order lamotrigine 200mg lamotrigine ca
sildenafil 50mg tablet order tadalafil 5mg sale buy generic cialis 5mg
empire city casino online live casino slots online modafinil 100mg cheap
generic prednisone 20mg order minipress 2mg generic order generic mebendazole
order terbinafine generic oral suprax 200mg amoxicillin cheap
biaxin usa catapres 0.1mg cost antivert 25mg cost
buy tiotropium bromide 9 mcg pills order spiriva 9 mcg hytrin 1mg without prescription
order pioglitazone 15mg without prescription purchase sildenafil pills order viagra 100mg without prescription
cialis 5mg for sale Canadian generic cialis empire city casino online
online blackjack gambling online blackjack casino free slot games for fun
black jack card game free where can i buy an essay write research paper for me
buy altace for sale amaryl 1mg sale etoricoxib 60mg generic
best essay writing websites write essay service azulfidine 500 mg sale
digoxin oral buy micardis 80mg pills molnunat online buy
carvedilol price order generic amitriptyline 50mg amitriptyline uk
cheap indocin cheap indomethacin 75mg buy cenforce 50mg sale
brand pamelor 25 mg nortriptyline 25 mg drug order paroxetine 10mg sale
brand ropinirole order calcitriol online cheap trandate 100 mg sale
buy fenofibrate 200mg sale generic fenofibrate sildenafil 200mg for sale
tadalafil 40mg over the counter Cialis prescription buy viagra 100mg online
buy glycomet 500mg for sale glycomet tablet buy tamoxifen 20mg sale
tadalafil 20mg Best cialis price where to buy ed pills
clomid 50mg price clomiphene without prescription buy prednisolone 5mg generic
accutane 10mg over the counter buy accutane 10mg pill buy ampicillin 250mg online cheap
ivermectin 12 mg without a doctor prescription stromectol 3mg pill order prednisone sale
prednisolone ca gabapentin 600mg price brand furosemide 40mg
buy monodox online vardenafil 10mg sale zovirax 800mg drug
avodart drug order keflex 500mg pill purchase orlistat generic
purchase zocor sale promethazine canada sildenafil pills 100mg
cefdinir medication purchase pantoprazole online order pantoprazole 40mg pill
cheap uroxatral 10mg order trazodone 100mg for sale diltiazem price
viagra order online price viagra order cialis 20mg pills
purchase levofloxacin pill bupropion 150 mg pill bupropion 150 mg drug
oral cenforce 100mg buy aralen 250mg online glycomet 1000mg canada
buy lipitor 80mg pill atorvastatin 10mg cheap viagra 100mg generic
real cialis pills cialis express delivery buy ed pills generic
tadalafil 10mg oral tadalafil women erection pills
cost provigil 200mg order promethazine 25mg pill order prednisone 5mg generic
buy amoxicillin sale prednisolone 5mg oral order prednisolone 10mg
buy zestril 2.5mg online cheap order zestril 2.5mg for sale lopressor 100mg pill
hyzaar pill buy nexium 40mg capsules topiramate online buy
order tamsulosin for sale buy ondansetron 8mg pills order aldactone 25mg
order combivent 100mcg pill buy decadron sale linezolid 600 mg without prescription
order duricef 250mg generic buy lamivudine without prescription order proscar 1mg online cheap
buy diflucan pills oral cipro cipro 1000mg pill
purchase metronidazole for sale cost flagyl 400mg keflex oral
order avanafil 100mg online avana uk where can i buy diclofenac
order tamoxifen 10mg pill ceftin us order ceftin 250mg generic
buy trimox cheap trimox cheap buy clarithromycin without prescription
catapres over the counter antivert 25mg cost buy spiriva pills for sale
sildenafil buy online brand sildenafil 100mg sildenafil pills 25mg
arava order buy azulfidine medication sulfasalazine 500 mg cheap
order azithromycin generic purchase gabapentin pills buy neurontin
buy lasix 100mg for sale cheap albuterol ventolin canada
generic levitra purchase hydroxychloroquine generic buy hydroxychloroquine 400mg generic
vardenafil without prescription buy tizanidine sale order generic plaquenil 200mg
olmesartan 20mg oral order depakote 250mg sale order generic depakote
order carvedilol without prescription order generic cenforce buy chloroquine 250mg without prescription
olumiant price order lipitor 20mg pills atorvastatin without prescription
order lopressor 100mg generic atenolol 50mg drug buy cheap generic methylprednisolone
acillin pills cost cipro metronidazole 200mg uk
order septra online buy generic keflex cleocin 150mg ca
budesonide nasal spray bimatoprost for sale online bimatoprost usa
oral aurogra order aurogra 50mg pills buy generic estrace over the counter
celebrex 100mg brand buy zofran generic order zofran online cheap
lamictal 50mg tablet order lamictal 50mg order prazosin 1mg pills
buy aldactone generic buy cheap generic zocor generic valacyclovir 500mg
buy retin gel for sale avana buy online buy avanafil 100mg generic
buy propecia 5mg generic sildenafil 50mg ca order viagra 100mg sale
generic tadalafil 20mg buy cialis 40mg online cheap viagra 50mg uk
tadalafil 20mg ca order tadalafil pill generic indomethacin
order terbinafine pill lamisil 250mg cheap order amoxicillin 250mg without prescription
buy sulfasalazine 500mg online azulfidine online order calan over the counter
arimidex over the counter buy catapres without a prescription catapres 0.1 mg pill
medicine for impotence buy viagra 100mg online sildenafil 50 mg
lansoprazole 15mg brand albuterol uk buy generic pantoprazole 40mg
buy cheap generic ed pills cheap tadalafil pills cost tadalafil 20mg
can i buy ed pills over the counter price of cialis tadalafil brand
buy amiodarone 100mg cordarone 200mg over the counter phenytoin tablet
oxybutynin 5mg us oxytrol online buy alendronate 35mg canada
macrodantin buy online generic motrin pamelor over the counter
order luvox 100mg pills purchase nizoral without prescription duloxetine 20mg for sale
cost acetaminophen 500mg order famotidine 40mg without prescription pepcid sale
trileptal generic cheap uroxatral 10 mg actigall 150mg sale
captopril 25 mg brand buy generic tegretol over the counter buy generic tegretol for sale
buy zyban sale order strattera 25mg generic order strattera 25mg generic
seroquel pills lexapro 20mg tablet buy escitalopram tablets
fluoxetine oral order femara 2.5 mg generic order letrozole generic
bisoprolol 10mg pills buy ethambutol no prescription order terramycin 250 mg online