- Notifications
You must be signed in to change notification settings - Fork 2
Auth
Laravel includes a comprehensive authentication implementation - documentation available here. This Doctrine2Bridge package includes a user provider which allows you to use Doctrine2 for your user database backend.
The following instructions will explain how to use this feature:
You need a database table to store your users and passwords. You can call this table anything you like. We include an example XML schema and generated entity in the examples/auth/ folder.
What you need to do is:
- create a table to hold your users;
- this table requires a column for usernames/emails and password;
- when this table is generated, add
implements \Illuminate\Auth\UserInterfaceto the class definition; - implement the
getAuthIdentifier()method which simply returns the object id; - implement the
getAuthPassword()method which returns the (hashed) password.
In your published Doctrine2Bridge configuration (config/d2bdoctrine.php), update the authentication section such as:
'auth' => array( 'enabled' => true, 'entity' => '\Entities\User' // the Doctrine2 entity representing the user )The entity element should be your Doctrine2 user entity class.
Now, update config/auth.php and set the driver:
'driver' => 'doctrine2bridge',That's it! You now have Doctrine2 / Laravel combined for authentication.
You can test this by adding a user:
$hasher = new Illuminate\Hashing\BcryptHasher; $u = new Entities\User(); $u->setUsername( 'testuser'); $u->setPassword( $hasher->make( 'qwertyuiop' ) ); D2EM::persist($u); D2EM::flush();To test the authentication:
echo 'Test failed authentication (result should be false): '; var_dump( Auth::attempt( array('username' => 'testuser', 'password' => 'dontknow') ) ); echo 'Test successful authentication (result should be true): '; var_dump( Auth::attempt( array('username' => 'testuser', 'password' => 'qwertyuiop') ) );And the expected output is:
Test failed authentication (result should be false): bool(false) Test successful authentication (result should be true): bool(true)