Generate random password di PHP bag. 2

Cara berikut akan menghasilkan output password yang lebih bervariasi dan lebih aman karena karakter- karakter seperti !@#$% dapat muncul.

Berikut adalah contoh codenya

<?php
function createPassword($panjang){

$huruf = “0123456789!@#$%&*()_-=+/abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”;

$password = “”;
$counter = 0;

while ($counter < $panjang) {
$length = strlen($huruf)-1;
$temp = rand(0,$length);
$randChar = substr($huruf,$temp,1);
$password .= $randChar;
$counter++;
}
return $password;
}
?>

Contoh hasil output dari fungsi diatas dengan input 10 : AJryzQK4#* , E(1hDVR#@3 dst.
Semoga bermanfaat.

This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>