# Authentication

**URL:** <https://discuss.rubyonrails.org/t/authentication/63758>\
**Category:** rubyonrails-talk\
**Created:** [May 1, 2012, 1:00pm UTC](https://discuss.rubyonrails.org/t/authentication/63758 "2012-05-01T13:00:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 1, 2012, 1:00pm UTC](https://discuss.rubyonrails.org/t/authentication/63758/1 "2012-05-01T13:00:50Z")

</div>

Application will not authenticate [sends alert of invalid credentials]. Using user credentials created via rake db:seed. How do I get it to authenticate?

Agent Model

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [May 1, 2012, 1:22pm UTC](https://discuss.rubyonrails.org/t/authentication/63758/2 "2012-05-01T13:22:14Z")

</div>

> Application will not authenticate [sends alert of invalid credentials]. Using user credentials created via rake db:seed. How do I get it to authenticate?

Which bit is not working? See the Rails Guide on debugging for help on how to debug your code.

Colin

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [May 1, 2012, 1:55pm UTC](https://discuss.rubyonrails.org/t/authentication/63758/3 "2012-05-01T13:55:53Z")

</div>

> Application will not authenticate [sends alert of invalid credentials]. Using user credentials created via rake db:seed. How do I get it to authenticate?
> 
> Agent Model ----------------
> 
> ```
> def Agent\.authenticate\(name,password\)
> if agent = find\_by\_name\(name\)
> if agent\.hash == encrypt\_password\(password,agent\.salt\)
> 
> ```

Have you tried calling agent.hash ? I'd wager that that methods returns something you don't expect, because hash is a method all ruby objects have - I suspect that you're calling that method rather than the one that would return the value of your hash column. You can get at the attribute value via read\_attribute, although I'd recommend avoiding dangerous names like that.

Fred

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 1, 2012, 6:28pm UTC](https://discuss.rubyonrails.org/t/authentication/63758/4 "2012-05-01T18:28:15Z")

</div>

Colin Law wrote in post #1059060:

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 1, 2012, 6:32pm UTC](https://discuss.rubyonrails.org/t/authentication/63758/5 "2012-05-01T18:32:59Z")

</div>

Frederick Cheung wrote in post #1059064:
