Last active
November 7, 2016 08:43
-
-
Save chihirokaasan/0b9f3cd807f77af5b064002503285a03 to your computer and use it in GitHub Desktop.
Making random password including number and symbol in Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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