Skip to content

Commit

Permalink
迁移random服务,解决app插件测试失败
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Dec 10, 2016
1 parent b3279b3 commit 14d8e03
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Service/Random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Miaoxing\App\Service;

use miaoxing\plugin\BaseService;

class Random extends BaseService
{
/**
* Generates random string
*
* @param int $length
* @return string
*/
public function string($length)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$str = '';
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}

/**
* Generates random password
*
* @param int $length
* @return string
*/
public function password($length)
{
$chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$str = '';
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
}

0 comments on commit 14d8e03

Please sign in to comment.