title: BCrypt::Errors::InvalidHash error in Rails
body: <p>code:</p>
  
  <pre><code>class LoginController &lt; ApplicationController
    def auth
          if params[:name].present? &amp;&amp; params[:pass].present? &amp;&amp; params[:role].present?
                  @name=params[:name]
                  pass=params[:pass]
                  role=params[:role]
  
                  epass = BCrypt::Password.new(pass)
          else
                  render "argerror"
          end
    end
  end
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>BCrypt::Errors::InvalidHash (invalid hash):
  app/controllers/login_controller.rb:12:in `new'
  app/controllers/login_controller.rb:12:in `auth'
  </code></pre>
  
  <p>Password Encryption Mechanism:</p>
  
  <pre><code>salt = BCrypt::Engine.generate_salt
  pass = BCrypt::Engine.hash_secret(pass, salt)
  </code></pre>
  
  <p>The above code product "BCrypt::Errors::InvalidHash" error. My requirement is to get the username and password from client and validate
  it with the data stored in db. In database I stored the hashed password for users which is encrypted by bcrypt. So, now I tried to
  encrypt the password which is entered by client. After encrypt the current password, it is matched with hashed password stored in db. But it produce the error. How to solve this problem ? </p>