# Login\_engine - auth against email rather that username?

**URL:** <https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846>\
**Category:** Rails\
**Created:** [January 2, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846 "2006-01-02T17:15:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/1 "2006-01-02T17:15:26Z")

</div>

Hi all,

Short of hacking the code apart, is there a method making the  
login\_engine authenticate against email address rather than username?

I find that people rarely remember usernames, and would prefer to use  
email addresses as the identifier.

Thanks!

Tom

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/2 "2006-01-02T17:15:35Z")

</div>

Simple fix would be to remove the email field from the  
app/view/signup.rhtml  
and rename the username field to email in the text.

What they put into the username field doesn’t much make a difference, as  
long as it is a string.

-Nb

```auto
 Nathaniel S. H. Brown http://nshb.net

```

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/3 "2006-01-02T17:15:43Z")

</div>

I think you have do a couple more things because the user model won’t  
validate if a login is not provided.

I just re-included the LoginEngine::AuthenticatedUser module in my  
User model and commented out the following lines:

# We aren’t using the login and need to comment it out

# validates\_presence\_of :login, :on =\> :create

# validates\_length\_of :login, :within =\> 3…40, :on =\> :create

# validates\_uniqueness\_of :login, :on =\> :create

Cheers,

Derek

On 1/2/06, Nathaniel S. H. Brown [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```auto
> > Hi all,
> >
> 
> ```

–  
Derek H.  
HighGroove Studios - [http://www.highgroove.com](http://www.highgroove.com)  
Atlanta, GA  
Keeping it Simple.  
404.593.4879

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/4 "2006-01-02T18:55:20Z")

</div>

Hello Tom !

2006/1/2, Tom T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Short of hacking the code apart, is there a method making the  
> login\_engine authenticate against email address rather than username?

I simply added a before\_validation filter that copies the email field  
to the username field. Then, I lenghtened the login field to  
accomodate E-Mails.

Hope that helps !

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/5 "2006-01-02T19:28:01Z")

</div>

This is all probably indicative of a need to distinguish the ‘user  
profile’ information (name, birthday, favourite colour) from the  
actual authentication information (id & password/phrase).

Perhaps the real way forward is either/or/both of:

a) removing the extraneous information (currently the name and email\*)  
from the authentication system, and  
b) giving developers a fairly intuitive means of defining their own  
validations on the id field - or a means of selecting between a few  
existing ones (login, email address, something else…)

The stealth-launched new site ([http://rails-engines.org](http://rails-engines.org)) has a link to  
the Trac system.  
Someone submit a ticket, close your eyes and click the heels of your  
ruby slippers three times, and perhaps it might get done 😉

- james

- note that removing the guarantee that one field will contain a valid  
email address means that email notification has to be reworked too.

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 2, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/6 "2006-01-02T20:24:27Z")

</div>

Tom T. wrote:

> Short of hacking the code apart, is there a method making the  
> login\_engine authenticate against email address rather than username?

Hi all,

Thanks for your responses. I’ve managed to make it work by just simply  
changing most instances of the ‘login’ variable to ‘email’ and  
removing/tweaking the validation lines. The code isn’t very complex, and  
a bit of following it all through did me some good.

In a future version, a flag in the config would be ideal, allowing you  
to auth against whatever field you wanted.

Login\_engine is great work though - saved me a lot of time writing my  
own system!

Thanks again,

Tom

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [January 3, 2006, 12:10am UTC](https://www.ruby-forum.com/t/login-engine-auth-against-email-rather-that-username/55846/7 "2006-01-03T00:10:04Z")

</div>

I was not inferring that he delete the login column and field, rather to  
remove the email field and use the login field for both the email and  
username.

I see under the validation that you would likely have to extend the  
length\_of below for the login field to more adequately compensate for  
the  
longer email addresses.

You still want to ensure that the email is unique, present,

So I suggest only modifying the following line in  
LoginEngine::Authenticated  
to the following.

```
    validates_length_of :login, :within => 5..255, :on => :create

```

Regards,  
Nathaniel.

```auto
 Nathaniel S. H. Brown http://nshb.net

```
