<?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>Blue Horn &#187; sfGuardPlugin</title>
	<atom:link href="http://bluehorn.co.nz/tag/sfguardplugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://bluehorn.co.nz</link>
	<description>New Zealand Web Design &#38; Development (PHP 5, MySQL, Symfony Framework, Apache, Linux)</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:23:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Implementing email login with sfGuardPlugin</title>
		<link>http://bluehorn.co.nz/2009/04/29/implementing-email-login-with-sfguardplugin/</link>
		<comments>http://bluehorn.co.nz/2009/04/29/implementing-email-login-with-sfguardplugin/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 08:44:12 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
				<category><![CDATA[Symfony Framework]]></category>
		<category><![CDATA[sfGuardPlugin]]></category>
		<category><![CDATA[symfony 1.0]]></category>
		<category><![CDATA[Symfony Resources]]></category>

		<guid isPermaLink="false">http://bluehorn.co.nz/?p=195</guid>
		<description><![CDATA[(* Update: This article is for Symfony 1.0, for Symfony 1.2 implementation go to Symfony 1.2, Propel, and sfGuardPlugin: email login) Most of us use sfGuardPlugin with Symfony Framework for user management (login stuffs). It is a great, popular, and de facto plugin for doing user management in Symfony. Here's the thing, by default, sfGuardPlugin [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>(<strong>* Update:</strong> This article is for Symfony 1.0, for Symfony 1.2 implementation go to <a href="/2009/06/12/symfony-12-propel-and-sfguardplugin-email-login/">Symfony 1.2, Propel, and sfGuardPlugin: email login</a>)</p>
<p>Most of us use <a href="http://www.symfony-project.org/plugins/sfGuardPlugin" target="_blank">sfGuardPlugin</a> with <a href="http://www.symfony-project.org/" target="_blank">Symfony Framework</a> for user management (login stuffs). It is a great, popular, and de facto plugin for doing user management in Symfony.</p>
<p>Here's the thing, by default, sfGuardPlugin does login using usernames, not emails. But for many projects, it is preferable and more suitable to use email for login.</p>
<p>In this article I would like to discuss a way to implement email login using Symfony. I've only tried this in Symfony 1.0,  but this might/should work on 1.1 and 1.2. And I would be very interested to know your experience if you try this method on Symfony 1.1 or Symfony 1.2<span id="more-195"></span></p>
<p><strong>AVOID USING USERNAME FIELD FOR STORING EMAIL!<br />
</strong></p>
<p>Although this is the quickest short cut, I believe that in the longer run, it is not worth it. It is a potential security and privacy issue (explained below), and your sfGuardPlugin is 'not compatible' with all the other plugins (also explained below).</p>
<p>Storing email in username field is a potential security and privacy issue. This is because username and email are two columns of different purposes.</p>
<p>Username tend to be displayed publicly, while email should never be displayed publicly. If you store email in username field, you have to be really careful when using other plugins that depend on sfGuardPlugin, because chances are, they’d display the email stored in username field publicly.</p>
<p>It is also not ‘natural’ to code things like: $this-&gt;sendEmailTo($user-&gt;getUsername());</p>
<p>Try to use sfGuardPlugin and sfSimpleForum, and store email in username field, and you’ll understand what I mean.</p>
<p><strong>So, here is my proposed way of implementing login using email </strong></p>
<p>Firstly, I've implemented this with <strong>Symfony 1.0</strong>! This might/should work with 1.1 and 1.2 but I have not tried it. If you do try it on 1.1 or 1.2, I would be interested to know your experience.</p>
<p>Secondly, you need to install sfGuardPlugin in your project first.</p>
<p><strong>1. Add few columns in user profile in schema.yml<br />
</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sf_guard_user_profile<span style="color: #339933;">:</span>
  _attributes<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> phpName<span style="color: #339933;">:</span> sfGuardUserProfile <span style="color: #009900;">&#125;</span>
  id<span style="color: #339933;">:</span>
  user_id<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> type<span style="color: #339933;">:</span> integer<span style="color: #339933;">,</span> foreignTable<span style="color: #339933;">:</span> sf_guard_user<span style="color: #339933;">,</span> foreignReference<span style="color: #339933;">:</span> id<span style="color: #339933;">,</span> required<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> onDelete<span style="color: #339933;">:</span> cascade <span style="color: #009900;">&#125;</span>
  first_name<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> type<span style="color: #339933;">:</span> varchar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> required<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span>
  last_name<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> type<span style="color: #339933;">:</span> varchar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> required<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span>
  email<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> type<span style="color: #339933;">:</span> varchar<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> required<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> unique<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then build your model, e.g.: symfony propel-build-all (<strong>WARNING</strong>: propel-build-all will wipe out all the records in the database of your project!!!!)</p>
<p><strong>2. Add retrieveByEmail in sfGuardUserProfilePeer.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> retrieveByEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">EMAIL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addJoin</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">USER_ID</span><span style="color: #339933;">,</span> sfGuardUserPeer<span style="color: #339933;">::</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span>sfGuardUserPeer<span style="color: #339933;">::</span><span style="color: #004000;">IS_ACTIVE</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">doSelectOne</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>3. Create new validator for checking login using email rather than username</strong></p>
<p>Save this as "sfGuardUserByEmailValidator.class.php" in lib folder of your project.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sfGuardUserByEmailValidator <span style="color: #000000; font-weight: bold;">extends</span> sfValidator
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> initialize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// initialize parent</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// set defaults</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username_error'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email or password is not valid.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password_field'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remember_field'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remember'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$password_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password_field'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password_field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$remember</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$remember_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remember_field'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$remember</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$remember_field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$profile</span> <span style="color: #339933;">=</span> sfGuardUserProfilePeer<span style="color: #339933;">::</span><span style="color: #004000;">retrieveByEmail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$profile</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$profile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getsfGuardUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// user exists and active?</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> and <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsActive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// password is ok?</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checkPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">signIn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$remember</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameterHolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username_error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>4. Override sfGuardAuth config</strong></p>
<p>Save this as 'apps/frontend/modules/sfGuardAuth/validate/signin.yml' (create folders if not already exist in your project).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">methods<span style="color: #339933;">:</span>
  post<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>username<span style="color: #339933;">,</span> password<span style="color: #009900;">&#93;</span>
&nbsp;
names<span style="color: #339933;">:</span>
  username<span style="color: #339933;">:</span>
  required<span style="color: #339933;">:</span>         <span style="color: #009900; font-weight: bold;">true</span>
  required_msg<span style="color: #339933;">:</span>     Your username is required
  validators<span style="color: #339933;">:</span>       <span style="color: #009900;">&#91;</span>userValidator<span style="color: #009900;">&#93;</span>
&nbsp;
password<span style="color: #339933;">:</span>
  required<span style="color: #339933;">:</span>         <span style="color: #009900; font-weight: bold;">true</span>
  required_msg<span style="color: #339933;">:</span>     Your password is required
&nbsp;
userValidator<span style="color: #339933;">:</span>
  <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">:</span>            sfGuardUserByEmailValidator
  param<span style="color: #339933;">:</span>
    password_field<span style="color: #339933;">:</span> password
    remember_field<span style="color: #339933;">:</span> remember</pre></div></div>

<p><strong>5. Execute symfony cc.</strong></p>
<p>That's it for the login mechanism.</p>
<p><strong>What to store in the username column then?</strong></p>
<p>I use up to 10 characters of first name, 3 characters of last name, and a 3-digits random number for usernames.</p>
<p>Use this function to generate unique username for a new user:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> findUniqueUsername<span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$last_name</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>sfGuardUserPeer<span style="color: #339933;">::</span><span style="color: #004000;">retrieveByUsername</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Closing</strong></p>
<p>Phew this is a long article! Please do share with me if you try this on Symfony 1.1 or 1.2.</p>
<p><strong>* Update:</strong> This article is for Symfony 1.0, for Symfony 1.2 implementation go to <a href="/2009/06/12/symfony-12-propel-and-sfguardplugin-email-login/">Symfony 1.2, Propel, and sfGuardPlugin: email login</a></p>
<p>Happy Symfonying!!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bluehorn.co.nz/2009/04/29/implementing-email-login-with-sfguardplugin/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

