Skip to content

Instantly share code, notes, and snippets.

@UnderlineWords
Forked from hlashbrooke/function.php
Created July 26, 2021 07:59
Show Gist options
  • Save UnderlineWords/ddc6007d7697cebf1279c8c35e8dec09 to your computer and use it in GitHub Desktop.
Save UnderlineWords/ddc6007d7697cebf1279c8c35e8dec09 to your computer and use it in GitHub Desktop.
Simple way to generate a random string/password in PHP
<?php
function random_password( $length = 8 ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
$password = substr( str_shuffle( $chars ), 0, $length );
return $password;
}
?>
<?php $password = random_password(8); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment