PHPackages                             webiik/account - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. webiik/account

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

webiik/account
==============

The Account provides common interface for user authentication.

1.2(6y ago)014MITPHPPHP &gt;=7.2

Since Mar 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/webiik/account)[ Packagist](https://packagist.org/packages/webiik/account)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-account/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (4)Used By (0)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)

Account
=======

[](#account)

The Account provides common interface for user authentication.

Installation
------------

[](#installation)

```
composer require webiik/account

```

Example
-------

[](#example)

> The following example expects you have already written [your account implementation](#writing-your-custom-account) and you use email and password for user authentication.

```
$account = new \Webiik\Account\Account();

// Add your account implementation
$account->addAccount('YourAccount', function () {
	return new \Webiik\Service\YourAccount());
});

// Use one of your account implementations
$account->useAccount('YourAccount');

// Try authenticate a user
try {
    $user = $this->account->auth([
        'email' => 'kitty@webiik.com',
        'password' => 'meow!'
    ]);
    echo 'User ID: ' . $user->getId() . '';
    echo 'User status: ' . $user->getStatus() . '';
    echo 'User role: ' . $user->getRole() . '';

    if ($user->hasRole('admin')) {
        // Do something...
    }

} catch (AccountException $e) {
    echo $e->getMessage() . '';
    print_r($e->getValidationResult());
}

```

Settings
--------

[](#settings)

### addAccount

[](#addaccount)

```
addAccount(string $name, callable $accountFactory): void

```

**addAccount()** adds [an implementation](#writing-your-custom-account) of account.

```
$account->addAccount('YourAccount', function () {
	return new \Webiik\Service\YourAccount());
});

```

### useAccount

[](#useaccount)

```
useAccount(string $name): void

```

**useAccount()** sets account to be used when calling custom account related methods.

```
$account->useAccount('YourAccount');

```

### setNamespace

[](#setnamespace)

```
setNamespace(string $namespace): void

```

**setNamespace()** sets authentication namespace. It allows you to use separate authentication for different parts of your application. If you don't set any namespace, it means user belongs to default namespace.

```
// Set namespace to 'en'
$account->setNamespace('en');

// Let's say, user 'kitty@webiik.com' is authenticated in
// namespace 'es', so the following authentication fails.
try {
    $user = $this->account->auth([
        'email' => 'kitty@webiik.com',
        'password' => 'meow!'
    ]);
} catch (AccountException $e) {
    echo $e->getMessage(); // e.g. Account does not exist.
}

```

Writing Your Custom Account
---------------------------

[](#writing-your-custom-account)

To write your account implementation you have to extend from abstract class [AccountBase](AccountBase.php) and write your own implementation of methods **auth, signup, update, disable, delete, createToken, activate** and **resetPassword**. Don't forget to incorporate authentication [namespace](#setnamespace) to each method. Read below intended function of each mentioned method and adapt your implementation to it.

### auth

[](#auth)

```
auth(array $credentials): User

```

**auth()** authenticates a user with **credentials**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, INVALID\_CREDENTIAL, INVALID\_PASSWORD, ACCOUNT\_DOES\_NOT\_EXIST, ACCOUNT\_IS\_NOT\_ACTIVATED, ACCOUNT\_IS\_BANNED, ACCOUNT\_IS\_DISABLED, FAILURE

```
try {
    $user = $this->account->auth([
        'email' => 'kitty@webiik.com',
        'password' => 'meow!'
    ]);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

> To compare passwords, always use secure method `verifyPassword(string $password, string $hash): bool` provided by [AccountBase](#writing-your-custom-account).

### reAuth

[](#reauth)

```
reAuth(string $uid): User

```

**reAuth()** re-authenticates a user by unique user identifier **uid**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, ACCOUNT\_DOES\_NOT\_EXIST, ACCOUNT\_IS\_NOT\_ACTIVATED, ACCOUNT\_IS\_BANNED, ACCOUNT\_IS\_DISABLED, FAILURE

```
try {
    $user = $this->account->reAuth('d4rjke8');
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### signup

[](#signup)

```
signup(array $credentials): User

```

**signup()** signs up a user with **credentials**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, INVALID\_CREDENTIAL, ACCOUNT\_ALREADY\_EXISTS, FAILURE

```
try {
    $user = $this->account->signup([
        'email' => 'kitty@webiik.com',
        'password' => 'meow!'
    ]);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

> Never store passwords in plain text. [AccountBase](#writing-your-custom-account) provides you secure method to hash passwords `hashPassword(string $password): string`.

### update

[](#update)

```
update(int $uid, array $data): User

```

**update()** updates **data** on account with id **uid**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, ACCOUNT\_DOES\_NOT\_EXIST, INVALID\_KEY, FAILURE

```
try {
    $user = $this->account->update(1, [
    	'email' => 'nyan@webiik.com',
    ]);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### disable

[](#disable)

```
disable(int $uid, int $reason, array $data = []): User

```

**disable()** sets account status to ACCOUNT\_IS\_DISABLED or ACCOUNT\_IS\_BANNED on account with id **uid**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, ACCOUNT\_DOES\_NOT\_EXIST, FAILURE

```
try {
    $user = $this->account->disable(1, \Webiik\Account\AccountBase::ACCOUNT_IS_BANNED);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### delete

[](#delete)

```
delete(int $uid, array $data = []): User

```

**delete()** deletes an account with id **uid**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, ACCOUNT\_DOES\_NOT\_EXIST, FAILURE

```
try {
    $user = $this->account->delete([
        'uid' => 1,
    ]);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### createToken

[](#createtoken)

```
createToken(): string

```

**createToken()** creates and returns time limited security token. On error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, FAILURE

```
try {
    $token = $this->account->createToken();

    // Send token to user, so he can perform an action...

} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### activate

[](#activate)

```
activate(string $token): User

```

**activate()** activates an account by valid **token**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, INVALID\_TOKEN, FAILURE

```
try {
    $user = $this->account->activate($token);
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

### resetPassword

[](#resetpassword)

```
resetPassword(string $token, string $password): User

```

**resetPassword()** updates account **password** by valid **token**. On success returns [User](#user), on error throws [AccountException](#account-exception). Possible exception status codes: METHOD\_IS\_NOT\_IMPLEMENTED, INVALID\_TOKEN, FAILURE

```
try {
    $user = $this->account->resetPassword($token, 'new-password');
} catch (AccountException $e) {
    echo $e->getMessage();
}

```

> Never store passwords in plain text. [AccountBase](#writing-your-custom-account) provides you secure method to hash passwords `hashPassword(string $password): string`.

User
----

[](#user)

User is an object returned by several Account methods. User provides handy methods to work with authenticated user.

### \_\_construct

[](#__construct)

```
__construct(int $status, $id, string $role = '', array $info = [])

```

**\_\_construct()** creates User object.

**Parameters**

- **status** user account status. Usual status codes are: ACCOUNT\_IS\_OK and ACCOUNT\_IS\_NOT\_ACTIVATED
- **id** unique user account id.
- **role** (optional) user role.
- **info** (optional) additional user account info.

```
$user = new User(self::ACCOUNT_IS_OK, 1, 'user');

```

### getId

[](#getid)

```
getId()

```

**getId()** returns unique user account id.

```
$uid = $user->getId();

```

### getRole

[](#getrole)

```
getRole(): string

```

**getRole()** returns user role.

```
$role = $user->getRole();

```

### hasRole

[](#hasrole)

```
hasRole(string $role): bool

```

**hasRole()** checks if user has given **role**.

```
if ($user->hasRole('user') {
    // Do something...
}

```

### getInfo

[](#getinfo)

```
getInfo(): array

```

**getInfo()** returns additional user account info.

```
$info = $user->getInfo();

```

### needsActivation

[](#needsactivation)

```
needsActivation(): bool

```

**needsActivation()** checks if user account requires activation.

```
if ($user->needsActivation()) {
    // Send activation to user email
}

```

Account Exception
-----------------

[](#account-exception)

AccountException has to be thrown by all implemented account methods. Unlike standard Exception, AccountException has one extra parameter **validationResult**. This parameter is intended to store invalid credentials in the following format e.g. \['email' =&gt; \['Invalid email'\], 'password' =&gt; \['Password is too short.'\]\]

### \_\_construct

[](#__construct-1)

```
__construct($message = '', $code = 0, \Throwable $previous = null, array $validationResult = [])

```

**\_\_construct()** creates AccountException object.

```
throw new AccountException(self::MSG_INVALID_CREDENTIAL, self::INVALID_CREDENTIAL, null, ['email' => ['Invalid email'], 'password' => ['Password is too short.']]);

```

### getValidationResult

[](#getvalidationresult)

```
getValidationResult(): array

```

**getValidationResult()** returns invalid credentials.

```
try {
    $user = $this->account->auth([
        'email' => 'kitty@webiik.com',
        'password' => 'meow!'
    ]);
} catch (AccountException $e) {
    print_r($e->getValidationResult()); // e.g. ['email' => ['Invalid email'], 'password' => ['Password is too short.']]
}

```

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~189 days

Total

3

Last Release

2226d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (6 commits)")

---

Tags

Authenticationsignupsign up

### Embed Badge

![Health badge](/badges/webiik-account/health.svg)

```
[![Health](https://phpackages.com/badges/webiik-account/health.svg)](https://phpackages.com/packages/webiik-account)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[league/oauth2-client

OAuth 2.0 Client Library

3.8k118.6M1.2k](/packages/league-oauth2-client)[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k82.4M164](/packages/pragmarx-google2fa)[paragonie/sodium_compat

Pure PHP implementation of libsodium; uses the PHP extension if it exists

934131.6M155](/packages/paragonie-sodium-compat)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
