ClassGo
Auth\Storage\PasswordFile
class Auth\Storage\PasswordFile {
- public function __construct(string ...$paths);
- public function authenticate(string $key, string $secret): object;
- public function exists(): bool;
- public function users(): array;
}
Description
Auth\Storage\PasswordFile authenticates against an apache-format password file of `username:hash` lines, $path inside the application root; with no path it reads .htpasswd there. Lines may be bcrypt, argon2, apache md5 or {SHA}; the constructor refuses anything else and names the line.
Auth\Storage\PasswordFile is a class phpscript declares.
$object = new Auth\Storage\PasswordFile($paths);
Methods
public function authenticate(string $key, string $secret): object-
authenticate reports the user $key names when $secret is theirs.
A missing user and a wrong password are one answer and nothing a caller can see distinguishes them. What does distinguish them is time: a key the file does not carry costs no derivation, and one it carries costs whatever that line's format does. Closing that gap belongs to rate limiting, which bounds what any timing is worth; see docs/reference/extensions/hashing.md.
The go method
Authenticate. public function exists(): bool-
exists reports whether there is a user database to ask: the password file is there, and at least one of its lines is an account. A file of comments and blank lines alone answers false and a login page says there are no accounts where a form refusing every password would name no cause.
The go method
Exists. public function users(): array-
users is every record in the file, ordered by username.
It carries no hash and a script may hold it: everything above here sees a table of two columns, and the third column never leaves this package. A caller writes the rows into a table of its own and rebuilds it when the file changes.
The go method
Users.
Binding
- The go type
github.com/titpetric/phpscript/stdlib/auth.PasswordFile. - Registered by the package
github.com/titpetric/phpscript/stdlib/auth. - Built on
github.com/titpetric/phpscript/stdlib/auth.PasswordFile.