You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
946 B

4 months ago
<?php
namespace App\Support;
4 days ago
use Illuminate\Support\Str;
4 months ago
use Overtrue\Pinyin\Pinyin;
/**
4 days ago
* 场馆后台账号:用户名可用馆名拼音缩写;密码必须随机生成,不可由馆名推算。
4 months ago
*/
final class VenueAdminCredentials
{
/**
4 days ago
* 由场馆名称得到拼音首字母缩写(小写、仅字母数字),仅用于用户名。
4 months ago
*/
public static function acronymFromVenueName(string $name): string
{
$joined = Pinyin::abbr($name)->join('');
$joined = strtolower($joined);
$joined = preg_replace('/[^a-z0-9]/', '', $joined) ?? '';
return $joined !== '' ? $joined : 'v';
}
/**
4 days ago
* 随机强密码:每次不同,长度至少 12含大小写字母、数字与符号。
4 months ago
*/
4 days ago
public static function randomPassword(int $length = 16): string
4 months ago
{
4 days ago
$length = max(12, $length);
4 months ago
4 days ago
return Str::password($length, true, true, true, false);
4 months ago
}
}