1 <?php
2 /* --------------------------------------------------------------
3 CustomerPassword.inc.php 2015-01-30 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('CustomerPasswordInterface');
13
14 /**
15 * Value Object
16 *
17 * Class CustomerPassword
18 *
19 * Represents a customer password
20 *
21 * @category System
22 * @package Customer
23 * @subpackage ValueObjects
24 * @implements CustomerPasswordInterface
25 */
26 class CustomerPassword implements CustomerPasswordInterface
27 {
28 /**
29 * Customer's password.
30 * @var string
31 */
32 protected $md5password;
33
34
35 /**
36 * Constructor for the class CustomerPassword.
37 *
38 * Validates password and build md5-hash.
39 *
40 * @param string $p_password Customer's password.
41 * @param bool $p_disableHash (optional) Will not hash the provided password string.
42 *
43 * @throws InvalidArgumentException If $p_password is not a string.
44 */
45 public function __construct($p_password, $p_disableHash = false)
46 {
47 if(!is_string($p_password))
48 {
49 throw new InvalidArgumentException('$p_password is not a string');
50 }
51
52 if(!is_bool($p_disableHash))
53 {
54 throw new InvalidArgumentException('$p_disableHash is not a bool');
55 }
56
57 $this->md5password = ($p_disableHash === false) ? md5($p_password) : $p_password;
58 }
59
60
61 /**
62 * Returns the equivalent string value (MD5-hash).
63 * @return string Equivalent string value (MD5-hash).
64 */
65 public function __toString()
66 {
67 return $this->md5password;
68 }
69 }