FIX – Customer cannot login to magento 1.8.1

Following an upgrade to magento 1.8.1 on our development servers , we noticed that customers are unable to login to their account.

The issue is raising because the custom login form does not contain any form_key and there is a form key validation happening in loginPostAction of magento.

Here is the solution:

1 – Go to template/customer/form/login.phtml and template/persistent/customer/form/login.phtml and under

<ul class="form-list">

add the following code in the login form

 <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" /> 

If you are using the login form in different templates then you use add the form_key to the other parts as well.

I hope this helps.

EDIT:

- We are aware that this issue also exists while updating the qty of cart items, the same solution applies there.

- Previously there was two methods in this blog to fix the problem but editing core files goes against Magento development standards hence that has now been removed.

By
About the author: "I am the guy who's up all day and night working on projects and pushing the boundaries further everyday to give them magical outcome."
View all posts by Reza Moaiandin

52 Comments

  1. Thanks for this, however under which line do we add the code ?

  2. That works! My login.phtml was in ‘mytheme/template/persistent/customer/form’ – easy to find by turning on ‘Template Path Hints’

    Thanks

  3. thanks so much guys! 4 hour headache ended. mine also resided under perisistent/

  4. Many Thanks
    you save my life.

  5. Thanks! The first solution worked perfect for me.

  6. Hi Reza Moaiandin,

    Thanks a lot, solutions worked. As Marcus did, I had to follow template path and add that code into file. Thanks

  7. Worked perfectly. Thanks!

  8. Thank you very much, works perfect

  9. Thank a lot this solution worked fine thanks again

  10. Great Man It worked for me.. Thanks

  11. I didn’t think you could over-ride controllers like this? Models, sure, but not controllers. You’d have to build you’re own module wouldn’t you?

    • Thanks for mentioning that. Indeed, that is why I do not recommend it as I have mentioned in the post.

      I have now highlighted that in the post so people first attempt the first option. This issue is affecting other sections too (Shopping card qty update) so I am currently looking at where else this is happening and will update the post.

  12. Thank you so much I have been trying all day to fix this

  13. Yes ! Solved the problem :-)

  14. Hi Thanks Reza for the solution tips.. However..

    I have edited the forms in the following locations:
    /app/design/frontend/base/default/template/persistent/customer/form/login.phtml
    /app/design/frontend/base/default/template/customer/form/login.phtml
    but not making any difference.

    I am using the community edition of Magento ver. 1.8.1.0 .

    So I tried to do the Not Recommended method, but do not have the same directory structure as is quoted above: app/code/local/Mage/Customer/controllers/AccountController.php
    mine stops at: app/code/ and have either community or core as sub directories.

    Any help much appreciated.
    Thanks
    Mark

  15. Great solution!!
    Thnx

  16. Thank you very much, saved a lot of time :)

  17. thanks a lot guys! Works perfectly. My login form also under perisistent/

  18. Nice blog thanks it’s working but it’s not affected other things right in magento 1.8.1?

  19. Fantastic fix. Helped me after hours of searching (on 1.8.1.0), Thanks.

  20. Thanks a lot man. Really saved a lot of efforts.

    Just 1 more question. Initially login and logout both were not working but now this solution fixes the login thing but logout thing still reloads the page without logging out. Any help would be appreciated. Thanks.

    • Hey Chintan,

      I have not been able to replicate that Issue. I will have a look at that and will let you know if replicated.

  21. Thank you for this solution. I added it to my magento code and it work. Customers can now login. The issue, solved.
    Thanks again.

    -Outpour

  22. congratulations all for the excellent text – very good

  23. using the community edition of Magento ver. 1.8.1.0 .

    Edited the forms in the following locations:
    /app/design/frontend/base/default/template/persistent/customer/form/login.phtml
    /app/design/frontend/base/default/template/customer/form/login.phtml
    Not working

    tried to do the Not Recommended method,
    Still not workin .

    Please help using the community edition of Magento ver. 1.8.1.0 .

    • Have you tried clearing your cache? If you tried the not recommended method and still doesn’t work it’s probably your cache.

  24. Any update on how to fix the qty issue?

    Have you found other places that are effected due to this bug?

    Thanks!

    • It is the same issue. You will need to update the appropriate template file. I will write a little blog for that later next week.

  25. This worked for me after spending hours trying to solve! Thanks!

    Just a quick tip – make sure you clear all cache and history in your browser and delete all contents of var/cache/

    Sorted!

  26. Thanks!!

    First method works like a charm, probably many template developers will find your post useful!

  27. Yes, this works like a charm! (Magento CE 1.8.1.0)

    Thank you very much :)

  28. Thanks! This saved me a ton of tracing!

  29. Also add it to:

    /template/persistent/checkout/onepage/login.phtml

    and

    /template/persistent/checkout/onepagelogin.phtml

    if you use the standard checkout!

  30. Thanks tis works for me too, great solution.

  31. Hi,
    Thanks for posting this article.
    However i followed the instructions as mentioned in step 1 but i got this error message instead on the login page:
    Fatal error: Class ‘php echo Mage’ not found in /htdocs/public/www/app/design/frontend/default/template/persistent/customer/form/login.phtml on line 56

    Please how do i go about fixing this?
    Thanks in advance

  32. So iv added the line
    to both the forms and still no luck .. keeps kicking me back to the login page ?

    Any other idea’s will be of great help.

  33. I expected to find here the solution to my problem, but unfortunately it has not been so, your solution did not work for me.
    Users can not enter their accounts through the frontend. When they try to sign in, the page just refreshes but not enter, on your own account or through Facebook . The system will not show any errors or anything , just do not walk , so the reaction is the same when you put the correct data or when you put the wrong key on purpose , just refresh and nothing else.
    If you create a new user you can get in, but if you come back later you can not enter anymore, you’d have to go create a new user again.
    Now comes the strangest :
    If is given the case you are a new user, you have created an account and get to order , such order appears in the admin with a dummy user that I created a few days ago . That is, last clients, each one different , besides not receive any order confirmation email , their orders appear to me on the panel with my dummy user data , only the email of the client is correct, although them of course when ordering have entered their data. I have to say that I removed yesterday the dummy user but still appears.
    This is very frustrating and I don’t know how to solve it , so any opinion or clue about what might be happening is welcome.

    • Hi Nacho, This may be something other problem that needs solving. If you contact us we can try to look into it for you.

  34. It would be better if you would change your custom snippet to Magentos method which is

    getBlockHtml('formkey'); ?>

    Right after the tag

  35. Thanks Reza, solution 1 did the trick for me. I only updated the file under persistent though.

    Regards, Werner

  36. Thanks a ton!!!!

  37. This worked perfectly, thank you!

  38. I’ve been looking for a solution for days – I didn’t write the template that this website runs, so I didn’t even consider this. THANK YOU!

  39. Hi,
    So thanks, But it doesn’t wotk for me! i have still the problem.
    can you help me? i used joomlart magento template!

    • Hi, make sure you are editing the write template file. If you want to see that you are either use a Magento developer tools and look if the right template file is being opened or alternatively you can just put a random text in that template and see if it is being printed if not then either you are seeing the cached version or you are not editing the right file.

  40. Hey, Bro. Thanks for the solution! You have a small typo on the suggested solution #1. Add “php” to the opening tag (currently is only “<?").

  41. Had to use method two for a one page checkout template but saved my site!

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>