Last active
August 29, 2015 14:25
-
-
Save Osukaru/bba1feea15a4d4b0f228 to your computer and use it in GitHub Desktop.
Password Value Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User | |
{ | |
protected $username; | |
protected $password; | |
public function __construct($username, Password $password) | |
{ | |
$this->username = $username; | |
$this->password = $password; | |
} | |
public function username() | |
{ | |
return $this->username; | |
} | |
public function password() | |
{ | |
return $this->password; | |
} | |
public function changePassword(Password $password) | |
{ | |
$this->password = $password; | |
} | |
} | |
class Password | |
{ | |
protected $md5; | |
protected $sha1; | |
public function __construct($md5, $sha1) | |
{ | |
$this->md5 = $md5; | |
$this->sha1 = $sha1; | |
} | |
public function md5() | |
{ | |
return $this->md5; | |
} | |
public function sha1() | |
{ | |
return $this->sha1; | |
} | |
public static function generate($salt) | |
{ | |
return new self(md5($salt), sha1($salt)); | |
} | |
} | |
$user = new User( | |
$data['username'], | |
new Password($data['pass_md5'], $data['pass_sha1']) | |
); | |
$user->changePassword(Password::generate($request->get('password'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment