SaltService::UrlDecodeSalt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
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(openssl_random_pseudo_bytes($length)), 0, $length);
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, '/') !== false) {
20
      $salt = $this->GenerateSalt();
21
    }
22
23
    return $salt;
24
  }
25
}
26