# Validates\_uniqueness\_of not working - urgent

**URL:** <https://www.ruby-forum.com/t/validates-uniqueness-of-not-working-urgent/146505>\
**Category:** Rails\
**Created:** [August 21, 2008, 8:05pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-not-working-urgent/146505 "2008-08-21T20:05:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [August 21, 2008, 8:05pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-not-working-urgent/146505/1 "2008-08-21T20:05:51Z")

</div>

I’m using restful\_authentication to let users register and login.  
Lately, however, I’m seeing multiple login and emails being created  
even though I have validates\_uniqueness\_of as below:

user.rb  
validates\_uniqueness\_of :login, :email, :case\_sensitive =\> false

mysql\> select id, login, email, created\_at, state from users;  
±—±--------------±---------------------------  
±--------------------±--------+  
| id | login | email |  
created\_at | state |  
±—±--------------±---------------------------  
±--------------------±--------+  
| 1 | sthapit | removed\_email\_address@domain.invalid | 2008-02-08  
06:15:00 | active |  
.  
.  
.  
| 34 | changed1 | removed\_email\_address@domain.invalid | 2008-07-20  
06:35:35 | pending |  
| 35 | changed1 | removed\_email\_address@domain.invalid | 2008-07-20  
06:35:40 | active |  
| 38 | changed2 | removed\_email\_address@domain.invalid | 2008-08-15  
11:40:38 | pending |  
| 39 | changed2 | removed\_email\_address@domain.invalid | 2008-08-15  
11:40:43 | pending |  
.  
.  
±—±--------------±---------------------------  
±--------------------±--------+

If anyone has an idea why this is happening it would be very  
appreciated. (login and emails changed in the table above, but id,  
created\_at, and state are accurate).

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [August 21, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-not-working-urgent/146505/2 "2008-08-21T20:25:47Z")

</div>

On 21 Aug 2008, at 19:05, vince [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m using restful\_authentication to let users register and login.  
> Lately, however, I’m seeing multiple login and emails being created  
> even though I have validates\_uniqueness\_of as below:

Have you checked they don’t differ only by a space or something? Other  
than that validates\_uniqueness\_of is vulnerable to race conditions. If  
you want a 100% reliable enforcement of this, use a unique index.

> user.rb  
> validates\_uniqueness\_of :login, :email, :case\_sensitive =\> false
