Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:52:56+00:00 2026-06-11T18:52:56+00:00

I am a Rails newbie. I am using has_secure_password in the user controller. I

  • 0

I am a Rails newbie.

I am using has_secure_password in the user controller. I realize it applies blowfish to store the password securely, but I want to have the password encrypted before it leaves the browser client. If this means the password is encrypted twice – that’s fine by me.

So, in a simple login form like the one below, how to I call a Javascript function I have already to apply MD5 to the password, before the form is submitted? Sure – I could just send ‘standard’ HTML and a onSubmit() javascript call, but surely there is a way to do this the ‘Rails Way’. How?

Thanks in advance!

<h1>Log In</h1>

<%= form_tag sessions_path do %>
  <div class="field">
    <%= label_tag :email %><br />
    <%= text_field_tag :email, params[:email] %>
  </div>
  <div class="field">
    <%= label_tag :password %><br />
    <%= password_field_tag :password %>
  </div>
  <div class="actions"><%= submit_tag "Log In" %></div>
<% end %>

UPDATE:

It seems like there is no ‘Rails Way’ to do this, so following the suggestion from Samar, I simply added a listener to the form click event using jQuery, after explicitly giving the form an id. Below is the complete code segment with changes and typo corrections included. Note that I am using my own MD5 library.

<h1>Log In</h1>

<%= form_tag sessions_path, :id => 'user_login_form' do %>
    <div class="field">
        <%= label_tag :email %><br />
        <%= text_field_tag :email, params[:email] %>
     </div>
    <div class="field">
        <%= label_tag :password %><br />
        <%= password_field_tag :password %>
    </div>
    <div class="actions"><%= submit_tag "Log In" %></div>
<% end %>

<script type="text/javascript">
    $("#user_login_form").click(function(){
        $("#password").val(EncryptMD5($("#password").val()));
    });
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:52:57+00:00Added an answer on June 11, 2026 at 6:52 pm

    Download cryptojs from http://code.google.com/p/crypto-js/ . If your password field has id “password” and submit button has id “form_submit”. Then do the following:

    <script type="text/javascript" src="crypto.js">
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js">
        <script>
        $("#form_submit").click(function){
        $("#password").val(CryptoJS.MD5($("#password").val()));
        });
        </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a jquery/rails newbie and I'm having trouble using .sortable(). I have expandable rows
rails 3 newbie, using Devise for auth... I want to create the following models:
another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
I am Rails newbie and having some trouble passing parameters to form. I have
I am a newbie to Rails and I have seen that to write HTML
I know I'm a newbie in Rails but this is the second day I'm
I'm a newbie to rails, and I have researched a whole day. I think
Rails newbie here so just want to be sure I'm doing this right. I
Rails newbie here. I have a list of items which can have a status
I'm still a newbie with Rails (and actually development period). I'm using Rails 3.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.