Completed
Push — master ( 8907c8...48c403 )
by Matthew
26s queued 10s
created

SaltService::GenerateSaltForUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace PhpDraft\Config\Security;
4
5
class SaltService {
6
  public function GenerateSalt() {
7
    //Special thanks: http://stackoverflow.com/a/18899561/324527
8
    $length = 16;
9
    return substr(base64_encode(mcrypt_create_iv(ceil(0.75*$length), MCRYPT_DEV_URANDOM)), 0, $length);
0 ignored issues
show
Deprecated Code introduced by
The function mcrypt_create_iv() has been deprecated: 7.1 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

9
    return substr(base64_encode(/** @scrutinizer ignore-deprecated */ mcrypt_create_iv(ceil(0.75*$length), MCRYPT_DEV_URANDOM)), 0, $length);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug introduced by
ceil(0.75 * $length) of type double is incompatible with the type integer expected by parameter $size of mcrypt_create_iv(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

9
    return substr(base64_encode(mcrypt_create_iv(/** @scrutinizer ignore-type */ ceil(0.75*$length), MCRYPT_DEV_URANDOM)), 0, $length);
Loading history...
10
  }
11
12
  public function UrlDecodeSalt($encoded_salt_value) {
13
    return str_replace(' ', '+', urldecode($encoded_salt_value));
14
  }
15
16
  public function GenerateSaltForUrl() {
17
    $salt = $this->GenerateSalt();
18
19
    while(strpos($salt, '/') != 0) {
20
      $salt = $this->GenerateSalt();
21
    }
22
23
    return $salt;
24
  }
25
}
26