Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Last active November 7, 2016 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihirokaasan/0b9f3cd807f77af5b064002503285a03 to your computer and use it in GitHub Desktop.
Save chihirokaasan/0b9f3cd807f77af5b064002503285a03 to your computer and use it in GitHub Desktop.
Making random password including number and symbol in Laravel 5
<?php
use Illuminate\Support\Collection;
class SampleController extends Controller
{
private function makeRandomPassword()
{
$collectionA = collect(range('a', 'z'))->random(4)->all();
$collectionB = collect(range('A', 'Z'))->random(4)->all();
$collectionC = collect(range(0, 9))->random(3)->all();
$collectionD = collect(['!','$','%','&','(',')','*','+','/'])->random(2)->all();//記号めんどくさいのでちょっと省略
$passwordstr = array_merge($collectionA,$collectionB,$collectionC,$collectionD);
return str_shuffle(implode($passwordstr));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment