pssht  latest
SSH server library written in PHP
Password.php
1 <?php
2 
3 /*
4 * This file is part of pssht.
5 *
6 * (c) François Poirotte <clicky@erebot.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 
13 
19 {
21  protected $password;
22 
24  protected $newPassword;
25 
26 
43  {
44  if (!is_string($password)) {
45  throw new \InvalidArgumentException();
46  }
47 
48  if (!is_string($newPassword) && $newPassword !== null) {
49  throw new \InvalidArgumentException();
50  }
51 
52  parent::__construct($user, $service, $method);
53  $this->password = $password;
54  $this->newPassword = $newPassword;
55  }
56 
57  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
58  {
59  parent::serialize($encoder);
60  $encoder->encodeBoolean($this->newPassword !== null);
61  $encoder->encodeString($this->password);
62  if ($this->newPassword !== null) {
63  $encoder->encodeString($this->newPassword);
64  }
65  return $this;
66  }
67 
68  protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
69  {
70  $passChange = $decoder->decodeBoolean();
71  $res = array($decoder->decodeString());
72  if ($passChange === true) {
73  $res[] = $decoder->decodeString();
74  }
75  return $res;
76  }
77 
84  public function getPassword()
85  {
86  return $this->password;
87  }
88 
96  public function getNewPassword()
97  {
98  return $this->newPassword;
99  }
100 }
__construct($user, $service, $method, $password, $newPassword=null)
Definition: Password.php:42
$user
User being authenticated.
Definition: Base.php:22
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: Password.php:57
$password
Password for the given login.
Definition: Password.php:21
$service
Service to start after authentication.
Definition: Base.php:25