
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Achari.in &#187; Set Credentials using security.yml in Symfony 1.4</title>
	<atom:link href="http://www.achari.in/tag/Set-Credentials-using-security.yml-in-Symfony-1.4/feed" rel="self" type="application/rss+xml" />
	<link>http://www.achari.in</link>
	<description>achari.in is a programmer&#039;s blog maintained by Anoop S Achari. Tutorials focus on Google Map API Integration, Twitter OAuth, Facebook Integration, Jquery, JSE, SCJP Materials and other technical articles.</description>
	<lastBuildDate>Thu, 26 Jan 2012 08:58:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Set Credentials using security.yml in Symfony 1.4</title>
		<link>http://www.achari.in/set-credentials-using-security-yml-in-symfony-1-4</link>
		<comments>http://www.achari.in/set-credentials-using-security-yml-in-symfony-1-4#comments</comments>
		<pubDate>Fri, 28 May 2010 17:51:18 +0000</pubDate>
		<dc:creator>anoopsachari</dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[doctrine credentials]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc framework]]></category>
		<category><![CDATA[security.yml]]></category>
		<category><![CDATA[set credentials in symfony]]></category>
		<category><![CDATA[Set Credentials using security.yml in Symfony 1.4]]></category>
		<category><![CDATA[symfony 1.4]]></category>

		<guid isPermaLink="false">http://www.achari.in/?p=343</guid>
		<description><![CDATA[Symfony provides some cool configuration features that would allow you to minimize your coding part .  In this tutorial i would explain how to configure security.yml to set credentials for a different users. Create a class file named account.class.php under apps/frontend/lib folder with content .The class below checks weather the user is admin and sets [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; padding-bottom:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.achari.in%2Fset-credentials-using-security-yml-in-symfony-1-4"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.achari.in%2Fset-credentials-using-security-yml-in-symfony-1-4&amp;source=anoopsachari&amp;style=normal&amp;service=TinyURL.com" height="61" width="50" /><br />
			</a>
		</div>
<p>Symfony provides some cool configuration features that would allow you to minimize your coding part .  In this tutorial i would explain how to configure security.yml to set credentials for a different users.</p>
<p><a href="http://www.achari.in/wp-content/uploads/2010/05/symfony.jpg"><img class="alignnone size-full wp-image-540" title="symfony" src="http://www.achari.in/wp-content/uploads/2010/05/symfony.jpg" alt="" width="570" height="250" /></a></p>
<p>Create a class file named account.class.php under apps/frontend/lib folder with content .The class below checks weather the user is admin and sets his credential as &#8216;admin&#8217; . Update the class file as your requirement .</p>
<pre class="brush: php;">

class account
{
 public static function getLoginAdmin($username, $password)
 {
 // code to check for username and password in a particular table : ORM is doctrine
 $usr = Doctrine::getTable('TableName')
 -&gt;createQuery('a')
 -&gt;where('a.adminuser = ?',$username)
 -&gt;andWhere('a.password = ?',$password)
 -&gt;execute();

 $login_user = count($usr);

 if($login_user &gt; 0)
 {
 sfContext::getInstance()-&gt;getUser()-&gt;setAuthenticated(true);
 sfContext::getInstance()-&gt;getUser()-&gt;addCredential('admin');

 return true;
 }
 else
 {
 return false;
 }
 }
 public static function LogoutSession()
 {
 sfContext::getInstance()-&gt;getUser()-&gt;setAuthenticated(false);
 sfContext::getInstance()-&gt;getUser()-&gt;clearCredentials();

 sfContext::getInstance()-&gt;getUser()-&gt;getAttributeHolder()-&gt;removeNamespace('admin');

 return true;
 }
}
</pre>
<p>And in login action file after receiving username and password call the library function as shown below</p>
<pre class="brush: php;">

$login_flag = account::getLoginAdmin($this-&gt;username,$this-&gt;password);
</pre>
<p>and if $login_flag returns true you have successfully logged in else enter username or password is invalid .</p>
<p>You have done with the class file and action page . Now you need to configure security.yml .</p>
<p>Create a folder named config inside a module ( say for eg : under admin module ) with security.yml in it and paste the following code .</p>
<pre class="brush: xml;">

index:
is_secure: true
credentials: admin
</pre>
<p>Now admin module can be accessed only by one with &#8216;admin&#8217; credential .</p>
<p>You can flush the credential as</p>
<pre class="brush: php;">

$logout = account::LogoutSession();
</pre>
<p>You are done !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.achari.in/set-credentials-using-security-yml-in-symfony-1-4/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

