本文整理匯總了PHP中Illuminate\Support\Str::random方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::random方法的具體用法?PHP Str::random怎麽用?PHP Str::random使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::random方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sampleUserProvider
public function sampleUserProvider()
{
$user = ["name" => "John", "password" => "chatbox1234"];
$hash = Str::random();
$user["email"] = "t.goto+{$hash}@chatbox-inc.com";
return [[$user]];
}
示例2: handle
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
parent::fire();
try {
if (cmsinstalled()) {
throw new \Exception('The CMS is already installed!');
}
$success = $this->r_installer->testDBConnection($this->argument('db-host'), $this->argument('db-name'), $this->argument('db-username'), $this->argument('db-password'));
if ($success) {
$this->r_installer->generateConfigs($this->argument('site-name'), $this->argument('site-description'), $this->argument('site-url'), $this->argument('db-host'), $this->argument('db-name'), $this->argument('db-username'), $this->argument('db-password'), $this->argument('user-first-name'), $this->argument('user-last-name'), $this->argument('user-email'));
$this->call('cache:clear');
$this->r_installer->migrate(['APP_SITE_NAME' => $this->argument('site-name'), 'APP_URL' => $this->argument('site-url')], ['--force' => true, '--database' => 'installer'], ['--force' => true, '--database' => 'installer']);
$password = Str::random(Settings::get('installer.password_length'));
$this->r_installer->addUserAdmin(['civility' => $this->argument('user-civility'), 'first_name' => $this->argument('user-first-name'), 'last_name' => $this->argument('user-last-name'), 'email' => $this->argument('user-email'), 'password' => $password]);
$this->r_installer->set_env_as_production();
$this->line(sprintf(trans('installer::installer.command_line_show_password'), $this->argument('user-email'), $password));
$this->line(trans('installer::installer.command_line_remember_change_password'));
} else {
$this->error(trans('installer::installer.error:db_connection'));
}
} catch (InvalidArgumentException $e) {
$this->error($e->getMessage());
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
示例3: token
/**
* Generates a random token
*
* @param String $str [description]
*
* @return String [description]
*/
function token($str = null)
{
$str = isset($str) ? $str : \Illuminate\Support\Str::random();
$value = str_shuffle(sha1($str . microtime(true)));
$token = hash_hmac('sha1', $value, env('APP_KEY'));
return $token;
}
示例4: store
/**
* Update the users profile
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = User::find($request->input('user_id'));
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->username = $request->input('username');
if ($request->input('password') != '') {
$user->password = bcrypt($request->input('password'));
}
$user->update();
$company = Company::where('user_id', $request->input('user_id'))->first();
$company->name = $request->input('company_name');
$company->description = $request->input('company_description');
$company->phone = $request->input('company_phone');
$company->email = $request->input('company_email');
$company->address1 = $request->input('company_address');
$company->address2 = $request->input('company_address2');
$company->city = $request->input('company_city');
$company->postcode = $request->input('company_postcode');
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$name = Str::random(25) . '.' . $file->getClientOriginalExtension();
$image = Image::make($request->file('logo')->getRealPath())->resize(210, 113, function ($constraint) {
$constraint->aspectRatio();
});
$image->save(public_path() . '/uploads/' . $name);
$company->logo = $name;
}
$company->update();
flash()->success('Success', 'Profile updated');
return back();
}
示例5: getRandomKey
/**
* Generate a random key for the application.
*
* @param string $cipher
* @return string
*/
protected function getRandomKey($cipher)
{
if ($cipher === 'AES-128-CBC') {
return Str::random(16);
}
return Str::random(32);
}
示例6: createNewToken
public function createNewToken(City $city)
{
$this->token = hash_hmac('sha256', Str::random(40), config('app.key'));
$this->city_id = $city->id;
$this->save();
return $this->token;
}
示例7: handle
/**
* Run the request filter.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->session()->has('sift_session_id')) {
$request->session()->put('sift_session_id', Str::random(24));
}
return $next($request);
}
示例8: run
public function run()
{
DB::table('projects')->delete();
Project::create(['name' => 'Deployer', 'hash' => Str::random(60), 'repository' => 'https://github.com/REBELinBLUE/deployer.git', 'url' => 'http://deploy.app', 'group_id' => 2, 'private_key' => '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAmrMjtajVvmd99T8xwUNrIFbrzSmZ6VCM89hfm4Ut9atv29gG
l2HFPJY7VtslXDJVL67w5EUMspy82tkAX7F03iaarSsbo6nC16UTfbfNTi44Snm0
T/5RMavSOnOMRJ8BQcfzqge4oIQzVGXOs0YvNFdSt4paBp9dssKS+7yP/hDvgAVz
+LE3IcIeO26aXATcuB4zq3vjaqSzWZGdNhOJZ4EmjgmOq9+k3SAmooHkF+p/14MJ
tq0ZK9KjSGbHfyKMi2EuvwllFCY19eqsV7dcMDIsMKUW2diFC52dJSO+EF47nA/j
sNDisFsIC7DeeVVBl1TpaV9RidqeZmdx+mF9AQIDAQABAoIBAH4qhYAdTx03eGGw
hVqSKmc4nJ05RX4kJKCmoerLZh1LETJh75Y8tchg2cpPdhvILPNzoKD6s41kCR4P
BqAEsUSQhWufka4bwH1w8wGACp+tUFllAqqOxhdVg2IKZKZ+a18DvPS50ViQGPDH
CxnorozoftyTqDJofNlSmN9X/LN+RZ1zRJRaPkBvSkYOCT4gnJLmHLGN7eJsHQeR
EJe83E4VPZ+2faBHEigXAHc4rh63iRxmmqqlcrItXzONZZUOjXwBNqZs4aVl+DZd
1pPiB9nOT9zLiy9ZwHZfIRIF3LkWAVsIkzOPDw9wLNgzI60uiLlYY1ODua8maqDP
m5eOT7ECgYEAzbVdEVngZd/jRlAo/LOLyy6NbZP4fli26hZjJBAJ8HhI93JEcxts
l/1E3rUME2a+F8CQ5FlGP02k66sB5lhzCg81Ym4fxbIP1n09IPmaRzSdM55SpbFy
7OV4VyrJKl7g2Y/utdb17DjYGovu+HX978j1iOH8qUruwAZyWshqdW0CgYEAwIVO
AohxuytN1GlQW4byQvHO4y+AXtZJ4iuBiyOqGhYs8bcnbV3+B0UTHtJyM8Novzj6
OcgiCEHP0Kj6Lj9RYu2sBvsgyfxEURdkHD7DPpYKlheCd7I1a9qk4/UyGx11YdnP
bcqrxv6e2FPBXNZGTXGBmHtIItxHYBEehguRLWUCgYALpR61or7fRYNaMaOAWrGp
OONstpm0nVUNf2LxYa8OW+DVkTRqx7yoBgBmEx2x43kTYyVQp/UgFEcnyDB9V7h7
c0z0W4OU73WSENjrCvY+3a2ghG/tTVRSMNNVK+jjayeTaWB8DsUxMC6bohxPGG7d
qiSsMQ7ajpFhcXv7w6izKQKBgQC+Pz0+vYz+NCXeQRAa0nj29LPIx7kofsRWTz3d
vKmsy7swRhkdN6P/lR/29mnKg1EwnmKP1RjkZfyyKznHl+SaSVoVL/dQAw2TwPS6
AL+6SlU9yw+vrxihc1g8uKICL5M+1hnoWj50EEvyZJoRXuHsR72UbEd1w454/ZHX
TvjxDQKBgCtikMNAqTParY/tX0xNohD7+svTKZt92CxW7Q/17H26ehFKUQvw6Agd
ulR2AVTGi6STEgzXf6UP5CAVhYRw9irCAQYpceL0GVzfZPQsXyLuMCnJ8UD6CBRn
i5vkNY4OZdOuEV9boFOFYa58WRNK7vthHkZJj++Amu3dZ6RHBlLQ
-----END RSA PRIVATE KEY-----', 'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCasyO1qNW+Z331PzHBQ2sgVuvNKZnpUIzz2F+bhS31q2/b2Aa' . 'XYcU8ljtW2yVcMlUvrvDkRQyynLza2QBfsXTeJpqtKxujqcLXpRN9t81OLjhKebRP/lExq9I6c4xEnwFBx/OqB7' . 'ighDNUZc6zRi80V1K3iloGn12ywpL7vI/+EO+ABXP4sTchwh47bppcBNy4HjOre+NqpLNZkZ02E4lngSaOCY6r3' . '6TdICaigeQX6n/Xgwm2rRkr0qNIZsd/IoyLYS6/CWUUJjX16qxXt1wwMiwwpRbZ2IULnZ0lI74QXjucD+Ow0OKw' . 'WwgLsN55VUGXVOlpX1GJ2p5mZ3H6YX0B deploy@deployer', 'last_run' => null, 'build_url' => 'http://ci.rebelinblue.com/build-status/image/3?branch=master']);
}
示例9: fire
/**
* Execute the console command.
* @throws Exception
*/
public function fire()
{
$login = $this->argument('login');
if ($this->rainlab) {
$rainlab = (bool) $this->option('rainlab');
} else {
$rainlab = false;
}
if ($rainlab) {
$user = \RainLab\User\Models\User::where('email', '=', $login)->orWhere('username', '=', $login)->first();
} else {
$user = User::whereLogin($login)->first();
}
if (!$user) {
return $this->error('User not found');
}
$password = $this->option('password');
if ($rainlab) {
$login = 'RainLab.User => ' . $login;
} else {
$login = 'Backend.User => ' . $login;
}
if ($password == null) {
$password = $this->ask('Set password for ' . $login . ' (or press Enter to skip)');
}
if ($password == null) {
$password = Str::random(5);
}
$user->update(['password' => $password, 'password_confirmation' => $password]);
$message = "\n -> new password for " . $login . ": ";
$this->comment($message . $password);
return;
}
示例10: create
/**
* @param string $fileType
*
* @return ImportJob
*/
public function create(string $fileType) : ImportJob
{
$count = 0;
$fileType = strtolower($fileType);
$keys = array_keys(config('firefly.import_formats'));
if (!in_array($fileType, $keys)) {
throw new FireflyException(sprintf('Cannot use type "%s" for import job.', $fileType));
}
while ($count < 30) {
$key = Str::random(12);
$existing = $this->findByKey($key);
if (is_null($existing->id)) {
$importJob = new ImportJob();
$importJob->user()->associate($this->user);
$importJob->file_type = $fileType;
$importJob->key = Str::random(12);
$importJob->status = 'import_status_never_started';
$importJob->extended_status = ['total_steps' => 0, 'steps_done' => 0, 'import_count' => 0, 'importTag' => 0, 'errors' => []];
$importJob->save();
// breaks the loop:
return $importJob;
}
$count++;
}
return new ImportJob();
}
示例11: updateUser
/**
* @param \Lio\Accounts\User $user
* @param \Lio\Accounts\UserUpdaterListener $listener
* @param array $data
* @return mixed
*/
private function updateUser(User $user, UserUpdaterListener $listener, array $data)
{
$oldEmail = $user->email;
$user->fill($data);
// If the email changed, the user will need to re-confirm it.
if ($data['email'] !== $oldEmail) {
$user->confirmed = false;
// Set a confirmation code for the user. He'll need to verify his email address
// with this code before he can use certain sections on the website.
$confirmationCode = Str::random(30);
// We'll generate a new one if we find a user with the same code.
while ($this->users->getByConfirmationCode($confirmationCode) !== null) {
$confirmationCode = Str::random(30);
}
$user->confirmation_code = $confirmationCode;
}
// check the model validation
if (!$this->users->save($user)) {
return $listener->userValidationError($user->getErrors());
}
// Send a confirmation email to the user.
if ($data['email'] !== $oldEmail) {
$this->confirmation->send($user);
}
return $listener->userUpdated($user, $data['email'] !== $oldEmail);
}
示例12: uniqueReference
/**
* Generate unique reference
*
* @return string
*/
public function uniqueReference()
{
do {
$reference = Str::upper(Str::random($this->referenceLength()));
} while (self::where($this->referenceField(), '=', $reference)->count() > 0);
return $reference;
}
示例13: generateUniqueName
protected function generateUniqueName($file, $path)
{
do {
$fileName = Str::random(20) . '.' . File::extension($file->getClientOriginalName());
} while (file_exists(public_path($path) . '/' . $fileName));
return $fileName;
}
示例14: createWish
public function createWish($user, $projectHash)
{
$project = $this->projectRepository->getByHash($projectHash);
$hash = Str::random(38);
$attrs = ['hash' => $hash, 'user_id' => $user->id, 'project_id' => $project->id];
$wish = $this->wishRepository->create($attrs);
return $wish;
}
示例15: src
/**
*
* @param null $config
* @return string
*/
public function src($config = null, $formId = false)
{
$this->configure($config, $formId);
if ($this->formId) {
return url('captcha' . ($config ? '/' . $config : '/default')) . '/' . $this->formId . '?' . $this->str->random(8);
}
return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8);
}