会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
天际翔龙
付出总有收获,虽然不一定是对自己有益的收获,但是不付出,连收获的权利都没有
博客园
首页
新随笔
联系
订阅
管理
生成随机密码函数
两个产生随机密码函数:
函数一:
function
randomPassword(
$passwordLength
=
8
)
{
$str
=
"
abcefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
"
;
if
(
$passwordLength
>
strlen
(
$str
))
$passwordLength
=
strlen
(
$str
);
if
(
$passwordLength
<
8
)
$passwordLength
=
8
;
$start
=
mt_rand
(
1
,
(
strlen
(
$str
)
-
$passwordLength
));
$string
=
str_shuffle
(
$str
);
$password
=
substr
(
$string
,
$start
,
$passwordLength
);
return
(
$password
);
}
函数二:
function
randomPassword(
$passwordLength
=
8
)
{
//
密码字符串
define
(
"
PASS_STRING
"
,
"
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
"
);
if
(
$passwordLength
<
8
)
$passwordLength
=
8
;
for
(
$i
=
1
;
$i
<=
$passwordLength
;
$i
++
)
{
$randomPosition
=
rand
(
0
,
strlen
(PASS_STRING)
-
1
);
$password
.=
substr
(PASS_STRING
,
$randomPosition
,
1
);
}
return
$password
;
}
posted @
2008-01-26 10:23
天际翔龙
阅读(
493
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告