Özelleştirilmiş Şifre Üretici

PHP
45 lines
<?php
class SifreUretici{
var $wc;
var $w;
var $l;
var $minl;
var $maxl;
function SifreUretici($min, $max, $dizi=NULL){
if($dizi == NULL){
$this->wc = array('_','-'); // special chars
for($i=48; $i<58; $i++){
array_push($this->wc, chr($i)); // 0-9
}
for($i=65; $i<91; $i++){
array_push($this->wc, chr($i)); // A-Z
}
for($i=97; $i<122; $i++){
array_push($this->wc, chr($i)); // a-z
}
shuffle($this->wc);
}
else{
$this->wc = $dizi;
}
$this->minl = $min;
$this->maxl = $max;
}
function olustur(){
$this->w = NULL;
$this->l = rand($this->minl, $this->maxl);
for($i=0; $i<$this->l; $i++){
$no = rand(0, count($this->wc)-1);
$this->w .= $this->wc[$no];
}
return htmlentities($this->w);
}
}
$s = new SifreUretici(10, 16); //10-16 karakter arası şifre üretir.
echo $s->olustur();
echo "<br>";
$dizi = array('a','b','1','!'); // Sadece bu karakterlerden 8 haneli şifre üretir
$s = new SifreUretici(8,8,$dizi);
echo $s->olustur();
echo "<br>";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
2 lines
f_aDfXWCmKK4t
!bb!1ab1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX