1 | <?php |
||
29 | class PasswordEncoder implements PasswordEncoderInterface |
||
|
|||
30 | { |
||
31 | |||
32 | /* @var $config array */ |
||
33 | public $config; |
||
34 | |||
35 | 1125 | public function __construct(array $config) |
|
39 | |||
40 | /** |
||
41 | * Encodes the raw password. |
||
42 | * |
||
43 | * @param string $raw The password to encode |
||
44 | * @param string $salt The salt |
||
45 | * |
||
46 | * @return string The encoded password |
||
47 | */ |
||
48 | 503 | public function encodePassword($raw, $salt) |
|
49 | { |
||
50 | 503 | if ($salt == '') { |
|
51 | $salt = $this->config['auth_magic']; |
||
52 | } |
||
53 | 503 | if ($this->config['auth_type'] == 'PLAIN') { |
|
54 | $res = $raw; |
||
55 | } else { |
||
56 | 503 | $res = hash_hmac($this->config['password_hash_algos'], $raw . ':' . $this->config['auth_magic'], $salt); |
|
57 | } |
||
58 | |||
59 | 503 | return $res; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Checks a raw password against an encoded password. |
||
64 | * |
||
65 | * @param string $encoded An encoded password |
||
66 | * @param string $raw A raw password |
||
67 | * @param string $salt The salt |
||
68 | * |
||
69 | * @return bool true if the password is valid, false otherwise |
||
70 | */ |
||
71 | public function isPasswordValid($encoded, $raw, $salt) |
||
96 | |||
97 | } |
||
98 |