windwalker / authenticate
Windwalker Authenticate package
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:windwalker-package
Requires
- php: >=5.3.10
Requires (Dev)
- windwalker/test: ~2.0
README
Installation via Composer
Add this to the require block in your composer.json
.
{ "require": { "windwalker/authenticate": "~2.0" } }
Getting Started
This is a simple login auth process.
public function login($username, $password) { $auth = new Authenticate; // Attach methods $auth->addMethod(new LocalMethod); $auth->addMethod(new MyMethod); $credential = new Credential; $credential->username = $username; $credential->password = $password; // Do authenticate $result = $auth->authenticate($credential); // False means login fail if (!$result) { // Print results to know what happened print_r($auth->getResults()); throw new Exception('Username or password not matched'); } $user = $auth->getCredential(); return $user; }
Create Custom Methods
use Windwalker\Authenticate\Method\AbstractMethod; class MyMethod extends AbstractMethod { public function authenticate(Credential $credential) { $username = $credential->username; $password = $credential->password; if (!$username || !$password) { $this->status = Authenticate::EMPTY_CREDENTIAL; return false; } $user = Database::loadOne(array('username' => $username)); if (!$user) { $this->status = Authenticate::USER_NOT_FOUND; return false; } if (!password_verify($password, $user->password)) { $this->status = Authenticate::INVALID_CREDENTIAL; return false; } // Success $this->status = Authenticate::SUCCESS; // Set some data to Credential $credential->bind($user); unset($credential->password); return true; } }