Skip to content

Instantly share code, notes, and snippets.

@JuniYadi
Created December 10, 2021 00:19
Show Gist options
  • Save JuniYadi/1beb32d6bdc6a592558b402231cedafc to your computer and use it in GitHub Desktop.
Save JuniYadi/1beb32d6bdc6a592558b402231cedafc to your computer and use it in GitHub Desktop.
<?php
function generate_password($int = 12) {
$length = 32;
if (PHP_VERSION>=7) {
$bytes= random_bytes($length);
} else {
$bytes= openssl_random_pseudo_bytes($length);
}
$string = bin2hex($bytes);
return substr($string, 0, $int);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment