-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathResult.php
100 lines (88 loc) · 1.95 KB
/
Result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Password Validator
*
* @link http://github.com/jeremykendall/password-validator Canonical source repo
* @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
* @license http://github.com/jeremykendall/password-validator/blob/master/LICENSE MIT
*/
namespace JeremyKendall\Password;
/**
* Password Validation Result
*
* Brazenly stolen from the Zend Framework then heavily modified.
* @see https://github.com/zendframework/zf2/blob/master/library/Zend/Password/Result.php
*/
class Result
{
/**
* General Failure
*/
const FAILURE = 0;
/**
* Failure due to invalid credential being supplied.
*/
const FAILURE_PASSWORD_INVALID = -3;
/**
* Password success.
*/
const SUCCESS = 1;
/**
* Password success, credential rehashed
*/
const SUCCESS_PASSWORD_REHASHED = 2;
/**
* Password result code
*
* @var int
*/
protected $code;
/**
* Rehashed password
*
* Only present if password was rehashed
*
* @var string
*/
protected $password;
/**
* Sets the result code and rehashed password
*
* @param int $code
* @param mixed $password
*/
public function __construct($code, $password = null)
{
$this->code = (int) $code;
$this->password = $password;
}
/**
* Returns whether the result represents a successful authentication attempt
*
* @return bool
*/
public function isValid()
{
return $this->code > 0;
}
/**
* getCode() - Get the result code for this authentication attempt
*
* @return int
*/
public function getCode()
{
return $this->code;
}
/**
* Returns the rehashed password
*
* Only present if password was rehashed
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
}