Skip to content

Instantly share code, notes, and snippets.

@olimortimer
Created July 30, 2013 14:14
Show Gist options
  • Save olimortimer/6113271 to your computer and use it in GitHub Desktop.
Save olimortimer/6113271 to your computer and use it in GitHub Desktop.
PHP: Random Password
<?php
function randomPassword($length = 8) {
$password = false;
$characters = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
$charsLength = strlen($characters) - 1;
for ($i = 0; $i < $length; $i++) {
$n = rand(0, $charsLength);
$password .= $characters[$n];
}
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment