生成随机密码方法有很多种,最简单的就是使用php mt_rand()函数来直接生成一串数字了,下面我来给大家介绍php生成随机密码程序
最简单的办法mt_rand函数.
mt_rand() 使用 Mersenne Twister 算法返回随机整数。
在本例中,我们会返回一些随机数,代码如下:
- <?php
- echo(mt_rand());
- echo(mt_rand());
- echo(mt_rand(10,100));
- ?>
- //输出类似:
- //3150906288
- //513289678
- //35
上面相对来说安全指数很低的,因为全是数字哦,下面另名一种
1、预置一个的字符串 $chars,包括 a – z,A – Z,0 – 9,以及一些特殊字符
2、在 $chars 字符串中随机取一个字符
实例代码如下
- 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;
- }
一个朋友提供的md5()函数的返回值的缘故,生成的密码只包括字母和数字,不过也算是一个不错的方法,算法思想:
1、time() 获取当前的 Unix 时间戳
2、将第一步获取的时间戳进行 md5() 加密
3、将第二步加密的结果,截取 n 位即得想要的密码
实例代码如下:
- function get_password( $length = 8 )
- {
- $str = substr(md5(time()), 0, 6);
- return $str;
- }
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php生成随机密码程序代码
波比源码 » php生成随机密码程序代码
Thank you for great content. Hello Administ. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
Thank you great post. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
Thank you for content. Area rugs and online home decor store. Hello Administ .Click on the Keyword to Enter the Website. tipobet
Thank you great posting about essential oil. Hello Administ . Hacklink Panel Hacklink
Good info. Lucky me I reach on your website by accident, I bookmarked it. Website Giriş için Tıklayin. onwin
484097 239742Hi there, just became aware of your weblog through Google, and located that its truly informative. Ill be grateful in case you continue this in future. Lots of people will benefit from your writing. Cheers! 683063
613136 362507Slide small cooking pot within the cable to make it easier for you to link the other big wooden bead for the conclude with the cord. 296713
Thank you great posting about essential oil. Hello Administ . 儿童色情片