Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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