首页 / PHP / php随机生成易于记忆的密码实例代码
php随机生成易于记忆的密码实例代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php随机生成易于记忆的密码实例代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1675字,纯文字阅读大概需要3分钟。
内容图文
![php随机生成易于记忆的密码实例代码](/upload/InfoBanner/zyjiaocheng/144/bb53c21abb26498c9b8ab0cd7e6e6861.jpg)
这篇文章主要介绍了php实现随机生成易于记忆的密码,实例分析了php生成随机密码的相关技巧,需要的朋友可以参考下
这里通过预定义一些单词,让php随机从这些单词中选择进行组合生成密码
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 随机生成易于记忆的密码实例代码的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的php随机生成易于记忆的密码实例代码全部内容,希望文章能够帮你解决php随机生成易于记忆的密码实例代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。