Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Created July 12, 2013 11:18
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save hlashbrooke/5983699 to your computer and use it in GitHub Desktop.
Save hlashbrooke/5983699 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