SaltService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A GenerateSalt() 0 4 1
A UrlDecodeSalt() 0 2 1
A GenerateSaltForUrl() 0 8 2
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