Skip to content

Instantly share code, notes, and snippets.

@Osukaru
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Osukaru/bba1feea15a4d4b0f228 to your computer and use it in GitHub Desktop.
Save Osukaru/bba1feea15a4d4b0f228 to your computer and use it in GitHub Desktop.
Password Value Object
<?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