Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Workshop\Step07;
- /**
- * @entity
- */
- class Auth extends SimpleEntity
- {
- /**
- * @OneToOne(targetEntity="Workshop\Step07\Person", inversedBy="auth")
- * @JoinColumn(name="person_id", referencedColumnName="id")
- */
- private $person;
- /** @Column(length=64) */
- private $username;
- /** @Column(length=64) */
- private $hash;
- public function setUsername($username)
- {
- if (!$username = self::filterUsername($username)) {
- throw new \Exception(__('Username is a required entry.'));
- }
- $this->username = $username;
- return $this;
- }
- public function setHash($hash)
- {
- if (!$hash = self::filterHash($hash)) {
- throw new \Exception(__('Password is a required entry.'));
- }
- $this->hash = $hash;
- return $this;
- }
- public function isEqualPassword($password)
- {
- return $this->hash == self::hash($password, $this->username);
- }
- public static function hash($password, $username)
- {
- if (!$username = self::filterUsername($username)) {
- throw new \Exception(__('Username is a required entry.'));
- }
- if (!$password = self::filterPassword($password)) {
- throw new \Exception(__('Password is a required entry.'));
- }
- return self::filterHash(hash_hmac('sha256', $password, $username));
- }
- }
Add Comment
Please, Sign In to add comment