PHP code example of dotkernel / dot-authentication-service
1. Go to this page and download the library: Download dotkernel/dot-authentication-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dotkernel / dot-authentication-service example snippets
//...
public function __construct(AuthenticationInterface $authentication)
{
$this->authentication = $authentication;
}
//...
public function someMethod()
{
if($this->authentication->hasIdentity()) {
//do something
}
}
public function prepare(ServerRequestInterface $request);
public function authenticate(): AuthenticationResult;
return [
'dot_authentication' => [
'adapter' => [
'type' => 'CallbackCheck',
'options' => [
// laminas db adapter service name
'adapter' => 'database service name',
'identity_prototype' => '\You\Identity\Class\Implementing\IdentityInterface',
'identity_hydrator' => '\Hydrator\Class\Implementing\HydratorInterface',
// your user table name
'table' => 'user table name',
// what user fields should use for authentication(db fields)
'identity_columns' => ['username', 'email'],
// name of the password db field
'credential_column' => 'password'
// we recommend using a service name or class name instead of closures
// the below closure is just an example, to show you the callable signature
// 'callback_check' => function($hash_passwd, $password) {
// return $hash_passwd === md5($password);
// }
],
],
//storage specific options, example below, for session storage
'storage' => [
'type' => 'Session',
'options' => [
//session namespace
'namespace' => 'dot_auth',
//what session member to use
'member' => 'storage'
],
],
'adapter_manager' => [
//register custom adapters here, like you would do in a normal container
],
'storage_manager' => [
//register custom storage adapters
],
'resolver_manager' => [
//define custom http authentication resolvers here
],
]
];