Notice
Recent Posts
Recent Comments
Link
Daniel's Knowledge Storage
php 패스워드 자동 생성 본문
<?php
/* *
* Function : string rand_pass()
*
* Purpose : Returns a random but pronounceable password.
* Note: You may edit the $num_letters and $array variables
*
* Author: Sebastien Cevey <seb@cine7.net>
* Project: Web OpenScripts <http://wos.sourceforge.net>;
* */
function rand_pass() {
# Pronounceable pieces of words
$array = array(
"ap","dus","tin","rog","sti","rev","pik","sty","lev","qot","rel","vid",
"kro","xo","pro","wia","axi","jer","foh","mu","ya","zol","gu","pli","cra",
"den","bi","sat","ry","qui","wip","fla","gro","tav","peh","gil","lot",
"kal","zan","noc","bat","tev","lun","pal","hom","cun","wos","vox"
);
# The number of letters
$num_letters = 6;
# Fraction of uppercased letters (randomized too...)
$uppercased = 3;
# Randomize on microseconds
mt_srand ((double)microtime()*1000000);
# Create random pass (too long for the moment)
for($i=0; $i<$num_letters; $i++)
$pass .= $array[mt_rand(0, (count($array) - 1))];
# Make sure there is not twice the same letter one after the other
for($i=1; $i<strlen($pass); $i++) {
if(substr($pass, $i, 1) == substr($pass, $i-1, 1))
$pass = substr($pass, 0, $i) . substr($pass, $i+1);
}
# Randomize the pass case [for each letter]
for($i=0; $i<strlen($pass); $i++) {
if(mt_rand(0, $uppercased) == 0)
$pass = substr($pass,0,$i) . strtoupper(substr($pass, $i,1)) . substr($pass, $i+1);
}
# Shorten it now
$pass = substr($pass, 0, $num_letters);
# Return the password
return $pass;
}
echo rand_pass();
?>
[출처] 패스워드 자동생성하기 |작성자 정연아빠
'Develop > PHP' 카테고리의 다른 글
php 문자열 간단하게 자르기 2가지 방법 (0) | 2009.09.01 |
---|---|
php 디렉토리와 하위 파일까지 한꺼번에 삭제하는 함수 (0) | 2009.08.31 |
php 메일링을 단체로 반복해서 보내는 경우 풀소스 및 설명 (0) | 2009.08.31 |
php+javascript 경매사이트 남은 시간 출력 (0) | 2009.08.31 |
php 문자열 자르기 간단한...한글 안 깨짐. (0) | 2009.08.31 |
Comments