# Acts\_as\_authenticated, bad password

**URL:** <https://www.ruby-forum.com/t/acts-as-authenticated-bad-password/114462>\
**Category:** Rails\
**Created:** [September 12, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/acts-as-authenticated-bad-password/114462 "2007-09-12T22:53:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 12, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/acts-as-authenticated-bad-password/114462/1 "2007-09-12T22:53:27Z")

</div>

I just installed this and for the most part it works great, and all in  
about 1/2 an hour! Nice. But I have just one small problem. I would  
have expected an error message if login fails, but it just stays on  
the login page. I tried adding an “else” to the login method of the  
AccountController, but the flash message doesn’t show up. I’m missing  
something obvious here probably…

def login  
return unless request.post?  
self.current\_user = User.authenticate(params[:login],  
params[:password])  
if logged\_in?  
if params[:remember\_me] == “1”  
self.current\_user.remember\_me  
cookies[:auth\_token] = { :value =\>  
self.current\_user.remember\_token , :expires =\>  
self.current\_user.remember\_token\_expires\_at }  
end  
redirect\_back\_or\_default(:controller =\> ‘/account’, :action =\>  
‘index’)  
flash[:notice] = “Logged in successfully”  
else #my added code  
flash[:warning] = ‘Login failed’ #my added code  
end #my added code  
end

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 13, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/acts-as-authenticated-bad-password/114462/2 "2007-09-13T14:28:15Z")

</div>

Hi

Try it:

```
if logged_in?
  if params[:remember_me] == "1"
    self.current_user.remember_me
    cookies[:auth_token] = { :value =>

```

self.current\_user.remember\_token , :expires =\>  
self.current\_user.remember\_token\_expires\_at }  
end  
redirect\_back\_or\_default(:controller =\> ‘/home’, :action =\>  
‘teste’)  
flash[:notice] = “Login successfully”  
else  
flash[:notice] = “Login ou senha failed”  
end

If you really need flash[:warning] because some specific formatation in  
your  
layout, you have change layout and add \<%= flash[:warning] %\>

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [September 13, 2007, 3:53am UTC](https://www.ruby-forum.com/t/acts-as-authenticated-bad-password/114462/3 "2007-09-13T03:53:47Z")

</div>

dailer wrote:

> ```
> flash[:notice] = "Logged in successfully"
> else    
> flash[:warning] = 'Login failed' #my added code
> 
> ```

I think most default/scaffold views in Rails only show notices

e.g.  
flash[:notice]

You probably need to improve your flash message code to include  
:warning, this was discussed recently on this list.  
[http://groups.google.com/group/rubyonrails-talk/search?hl=en&group=rubyonrails-talk&q=simple+exists%3F+question&qt\_g=Search+this+group](http://groups.google.com/group/rubyonrails-talk/search?hl=en&group=rubyonrails-talk&q=simple+exists%3F+question&qt_g=Search+this+group)

cheers,

Anthony R.
