title: Unable to update password with Bcrypt
body: <p>I've tried this many ways but it seems BCrypt is encrypting a users submitted password twice.</p>
  
  <p>When a user signs up- Bcrypt works great, and I am able to sign in. But when I try and update their password in my password_resets_controller, I'm no longer able to log in. My database shows that the password is being updated and hashed, but I can't sign in. </p>
  
  <p>I even removed the line <code>@customer.save</code>, yet my database is still showing that the password is being updated ! </p>
  
  <p>Is something being updated under the hood I'm not aware of? See relatd SO thread:
  <a href="https://stackoverflow.com/questions/17773350/updating-password-with-bcrypt">Updating password with BCrypt</a></p>
  
  <p><strong>In my Customer.rb</strong></p>
  
  <pre><code>require 'bcrypt'
  class Customer &lt; ActiveRecord::Base
    include BCrypt
  
    def password
      @password ||= Password.new(password_hash)
    end
  
    def password=(new_password)
      @password = Password.create(new_password)
      self.password_hash = @password
    end
  
    def self.authenticate(email, password)
      @customer = Customer.find_by_email(email)
      if @customer &amp;&amp; @customer.password == password
        return @customer
      else
        return nil
      end
    end
  end
  </code></pre>
  
  <p><strong>In my customer_controller, the create code that actually works</strong> </p>
  
  <pre><code>  require 'bcrypt'
   class CustomersController &lt; ApplicationController
  
    def create_customer_account_iphone
    @customer_count = Customer.where(email: params[:email]).size rescue nil
    if(@customer_count == 0 || @customer_count == nil ||)
      @customer = Customer.new(first_name: params[:first_name], email: params[:email])
      @customer.password = params[:password] //this calls my model methods
      @customer.save  //here I am saving
      unless (!@customer.save)
       respond_to do |format|
        msg = {:status =&gt; "SUCCESS", :messages =&gt; "Customer created", :data =&gt; @customer.as_json}
        format.json  { render :json =&gt; msg } # don't do msg.to_json
      end
    else
      respond_to do |format|
        msg = {:status =&gt; "FAILED", :messages =&gt; "Customer Not Saved"}
        format.json  { render :json =&gt; msg } # don't do msg.to_json
      end
    end
  
  
  def sign_in_iphone
  @customer = Customer.authenticate(params[:email], params[:password])
  unless (@customer == 0 || @customer == nil)
    respond_to do |format|
      msg = {:status =&gt; "SUCCESS", :message =&gt; "CUSTOMER", :data =&gt; @customer.as_json}
      format.json  { render :json =&gt; msg } # don't do msg.to_json
    end
    else
      respond_to do |format|
        msg = {:status =&gt; "FAILED"}
        format.json  { render :json =&gt; msg } # don't do msg.to_json
      end
    end
  end
  </code></pre>
  
  <p><strong>In my password_reset_controller</strong></p>
  
  <pre><code>class CustomerPasswordResetsController &lt; ApplicationController
  
     def edit
   @customer = Customer.find_by_password_reset_token!(params[:id])
  end
  
  
  def update
  @customer = Customer.find_by_password_reset_token!(params[:id])
  if @customer.password_reset_sent_at &lt; 2.hours.ago
    redirect_to new_customer_password_reset_path, :alert =&gt; "Password  reset has expired."
  else
    @customer.password_hash = BCrypt::Password.create(params[:password])
    # @customer.save
    unless !@customer.save
      redirect_to new_customer_password_reset_path, :alert =&gt; "Password has been reset!"
    else
      render :edit
    end
   end
  end
  </code></pre>
  
  <p><strong>In my password_reset.html.erb</strong> </p>
  
  <pre><code>&lt;%= form_for @customer, :url =&gt; customer_password_reset_path(params[:id]), :method =&gt; :patch  do |f| %&gt;
  &lt;% if @customer.errors.any? %&gt;
      &lt;div class="error_messages"&gt;
        &lt;h2&gt;Form is invalid&lt;/h2&gt;
        &lt;ul&gt;
          &lt;% for message in @customer.errors.full_messages %&gt;
              &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
          &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
  &lt;% end %&gt;
  &lt;div class="field"&gt;
    &lt;%= f.label :password %&gt;
    &lt;%= f.password_field :password %&gt;
  &lt;/div&gt;
  &lt;div class="field"&gt;
    &lt;%= f.label :password_confirmation %&gt;
    &lt;%= f.password_field :password_confirmation %&gt;
  &lt;/div&gt;
  &lt;div class="actions"&gt;&lt;%= f.submit "Update Password" %&gt;&lt;/div&gt;
  </code></pre>