zf2 authentication

http://samsonasik.wordpress.com/2013/05/
https://github.com/samsonasik/SanAuthWithDbSaveHandler/tree/master/src/SanAuthWithDbSaveHandler
http://samsonasik.wordpress.com/2013/05/29/zend-framework-2-working-with-authenticationservice-and-db-session-save-handler/

xem code o day
http://www.kdecom.com/simple-authentication-using-zend-framework-2/
// test auth
use Zend\Authentication\Storage;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\DbTable;
use Zend\Db\Adapter\Adapter;

$dbAdapter = $this->serviceLocator->get(‘Zend\Db\Adapter\Adapter’);

$authAdapter = new DbTable($dbAdapter, ‘users’, ‘username’, ‘password’, ‘MD5(?)’);
$authAdapter->setIdentity(‘admin’)
->setCredential(‘admin’);
$authService = new AuthenticationService(new Storage\Session(“auth”));
$authService->setAdapter($authAdapter);
$result = $authService->authenticate();
if ($result->isValid()) {
// set id as identifier in session
$userId = $authAdapter->getResultRowObject(‘id’)->id;
$authService->getStorage()
->write($userId.”da noi them vao”);

var_dump($userId);
$a= $authService->getStorage()->read();
var_dump($a);
} else {
var_dump(“k dung”);
}
return FALSE;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s