コード例 #1
0
 public function testGenerateToken()
 {
     $generator = new TokenGenerator();
     $t1 = $generator->generateToken(10);
     PHPUnit::assertEquals(10, strlen($t1));
     $t2 = $generator->generateToken(60, 'foo');
     PHPUnit::assertEquals(60, strlen($t2));
     PHPUnit::assertEquals('foo', substr($t2, 0, 3));
 }
コード例 #2
0
 protected function modifyAttributesBeforeCreate($attributes)
 {
     $token_generator = new TokenGenerator();
     // create a token
     if (!isset($attributes['apitoken'])) {
         $attributes['apitoken'] = $token_generator->generateToken(16, 'T');
     }
     if (!isset($attributes['apisecretkey'])) {
         $attributes['apisecretkey'] = $token_generator->generateToken(40, 'K');
     }
     // hash any password
     if (isset($attributes['password']) and strlen($attributes['password'])) {
         $attributes['password'] = Hash::make($attributes['password']);
     } else {
         // un-guessable random password
         $attributes['password'] = Hash::make($token_generator->generateToken(34));
     }
     return $attributes;
 }
コード例 #3
0
ファイル: UserRepository.php プロジェクト: CryptArc/xchain
 public function create($attributes)
 {
     if (!isset($attributes['uuid'])) {
         $attributes['uuid'] = Uuid::uuid4()->toString();
     }
     $token_generator = new TokenGenerator();
     // create a token
     if (!isset($attributes['apitoken'])) {
         $attributes['apitoken'] = $token_generator->generateToken(16, 'T');
     }
     if (!isset($attributes['apisecretkey'])) {
         $attributes['apisecretkey'] = $token_generator->generateToken(40, 'K');
     }
     // hash any password
     if (isset($attributes['password']) and strlen($attributes['password'])) {
         $attributes['password'] = Hash::make($attributes['password']);
     } else {
         // un-guessable random password
         $attributes['password'] = Hash::make($token_generator->generateToken(34));
     }
     return User::create($attributes);
 }
コード例 #4
0
 public function create($attributes)
 {
     // require user_id
     if (!isset($attributes['user_id']) or !$attributes['user_id']) {
         throw new Exception("User ID is required", 1);
     }
     // create a uuid
     if (!isset($attributes['uuid'])) {
         $attributes['uuid'] = Uuid::uuid4()->toString();
     }
     if (!isset($attributes['private_key_token'])) {
         // create a token
         $token_generator = new TokenGenerator();
         $token = $token_generator->generateToken(40, 'A');
         $attributes['private_key_token'] = $token;
     }
     if (!isset($attributes['address'])) {
         // create an address
         $new_address = $this->address_generator->publicAddress($attributes['private_key_token']);
         $attributes['address'] = $new_address;
     }
     return PaymentAddress::create($attributes);
 }