-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавлены новые Трэйты GenPassTrait, GuardTrait. update md5 регистр
- Loading branch information
Sashagm
committed
Jun 17, 2023
1 parent
08a2f9c
commit 2ca2a84
Showing
5 changed files
with
198 additions
and
159 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace Sashagm\Social\Traits; | ||
|
||
|
||
use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||
use App\Models\User; | ||
|
||
trait GenPassTrait | ||
{ | ||
|
||
|
||
|
||
private function generatePass() | ||
{ | ||
$method = config('socials.genPass.method'); | ||
$filter = config('socials.genPass.filter'); | ||
$secret = config('socials.genPass.secret'); | ||
|
||
switch ($method) { | ||
|
||
case 'bcrypt': | ||
$pass = bcrypt($this->generateString($filter)); | ||
break; | ||
|
||
case 'md5': | ||
if (config('socials.genPass.viewReg')){ | ||
$pass = strtoupper(md5($this->generateString($filter) . $secret)); | ||
} else { | ||
$pass = md5($this->generateString($filter) . $secret); | ||
} | ||
break; | ||
|
||
case 'password_hash': | ||
$pass = password_hash($this->generateString($filter), PASSWORD_DEFAULT); | ||
break; | ||
|
||
case 'sha1': | ||
$pass = sha1($this->generateString($filter)); | ||
break; | ||
|
||
case 'sha256': | ||
$pass = hash('sha256', $this->generateString($filter)); | ||
break; | ||
|
||
case 'base64': | ||
$pass = base64_encode($this->generateString($filter)); | ||
break; | ||
|
||
|
||
|
||
default: | ||
$pass = bcrypt($this->generateString($filter)); | ||
break; | ||
} | ||
|
||
return $pass; | ||
} | ||
|
||
private function generateString($filter) | ||
{ | ||
|
||
if (config('socials.genPass.default_gen')) { | ||
|
||
return config('socials.genPass.default_pass'); | ||
} else { | ||
|
||
switch ($filter) { | ||
|
||
case 'string': | ||
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
break; | ||
|
||
case 'number': | ||
$characters = '0123456789'; | ||
break; | ||
|
||
case 'hard': | ||
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
break; | ||
|
||
case 'hard-unique': | ||
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=[]{}|:;<>,.?/~'; | ||
break; | ||
|
||
case 'rus-string': | ||
$characters = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'; | ||
break; | ||
|
||
case 'rus-hard': | ||
$characters = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ0123456789'; | ||
break; | ||
|
||
case 'rus-unique': | ||
$characters = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ0123456789!@#$%^&*()_-+=[]{}|:;<>,.?/~'; | ||
break; | ||
|
||
default: | ||
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
break; | ||
} | ||
|
||
$minLength = config('socials.genPass.min'); | ||
$maxLength = config('socials.genPass.max'); | ||
$stableLength = config('socials.genPass.stable_length'); | ||
|
||
|
||
if ($stableLength) { | ||
$length = config('socials.genPass.length'); | ||
} else { | ||
$length = rand($minLength, $maxLength); | ||
} | ||
|
||
|
||
$string = ''; | ||
for ($i = 0; $i < $length; $i++) { | ||
$string .= $characters[rand(0, strlen($characters) - 1)]; | ||
} | ||
return $string; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.