title: Updating a User model resets password? Rails question
body: <p>In my controller, I try updating a user instance's <code>rank</code> attribute (integer). For example from 1 to 2.</p>
  
  <p>I do this by:</p>
  
  <pre><code>@user = User.find(params[:id])
  @user.rank = 2
  @user.save(:validate =&gt; false)
  </code></pre>
  
  <p>For some reason the password for the user being saved gets erased, so that they can log in to my site without a password at all.  I've tried with and without the <code>:validate =&gt; false</code> parameter.  </p>
  
  <p>Any reason why? help?  Thanks a bunch</p>
  
  <p>Model Code</p>
  
  <p>class User &lt; ActiveRecord::Base
      attr_accessor :password
      attr_accessible :login, :email, :fname, :lname, :password, :password_confirmation, :rank, :hours, :wars
      email_filter = /\A[\w+-.]+@[a-z\d-.]+.[a-z]+\z/i</p>
  
  <pre><code>validates :login, :presence =&gt; true, :length =&gt; { :maximum =&gt; 15, :minimum =&gt; 4 }, :uniqueness =&gt; true
  validates :fname, :presence =&gt; true, :length =&gt; {:minimum =&gt; 2 }
  validates :lname, :presence =&gt; true, :length =&gt; {:minimum =&gt; 2 }
  validates :email, :presence =&gt; true, :format =&gt; { :with =&gt; email_filter}, :uniqueness =&gt; { :case_sensitive =&gt; false }
  validates :password,  :presence =&gt; true, :confirmation =&gt; true, :length =&gt; { :within =&gt;4..40 }
  validates :lane_id, :presence =&gt; true
  
  before_save :encrypt_password
  has_many :reports
  has_many :accomplishments
  belongs_to :lane 
  
  
  def has_password?(submitted_password)
    encrypted_password == encrypt(submitted_password)
  end
  
  def self.authenticate(login, submitted_password)
    user = find_by_login(login)
    return nil  if user.nil?
    return user if user.has_password?(submitted_password)
  end
  
  def self.authenticate_with_salt(id, cookie_salt)
    user = find_by_id(id)
    (user &amp;&amp; user.salt == cookie_salt) ? user : nil
  end
  
  def current_report
    report = (Report.order("created_at DESC")).find_by_user_id(@user.id)
  end
  
  private
  
  def encrypt_password
    self.salt = make_salt if new_record?
    self.encrypted_password = encrypt(password)
  end
  
  def encrypt(string)
    secure_hash("#{salt}--#{string}")
  end
  
  def make_salt
    secure_hash("#{Time.now.utc}--#{password}")
  end
  
  def secure_hash(string)
    Digest::SHA2.hexdigest(string)
  end
  </code></pre>
  
  <p>end</p>