title: Hash password not saved in the password column
body: <p>I am trying to store hash password in my <code>users</code> table while registration. Please see my code:</p>
  
  <p><strong>users_controller.rb</strong></p>
  
  <pre><code>def login
    @title = 'Login'
    #render layout: 'login'
  end
  def create_login
    user = User.authenticate(params[:user][:username], params[:user][:password])
    if user
      log_in user
      redirect_to '/admin'
    else
      flash[:danger] = 'Invalid email/password combination' # Not quite right!
      redirect_to :back
    end
  end
  def register
      @user = User.new
      @title = 'Register'
    end
  
    def create_register
      params[:user][:uniq_id] = generate_uniq
      @user = User.new(create_user_params)
      #raise @user.inspect
      respond_to do |format|
        if @user.save
          format.html { redirect_to :success, success: 'Registration was successfully created.' }
          format.json { redirect_to :register, status: :created, location: @users }
        else
          format.html { render :register }
          format.json { render json: @users.errors, status: :unprocessable_entity }
        end
      end
    end
  
  private
  
  def create_user_params
      params.require(:user).permit(:uniq_id, :name, :username, :email, :password, :password_confirmation, :password_salt, :dob, :address)
    end
  </code></pre>
  
  <p><strong>register.html.erb</strong></p>
  
  <pre><code>&lt;%= form_tag("/register", method: "post") do %&gt;
          &lt;%#= form_tag(@user) do |f| %&gt;
           &lt;% if @user.errors.any? %&gt;
            &lt;div id="error_explanation"&gt;
              &lt;h2&gt;&lt;%= pluralize(@user.errors.count, "error") %&gt; prohibited this user from being saved:&lt;/h2&gt;
              &lt;ul&gt;
                &lt;% @user.errors.full_messages.each do |message| %&gt;
                  &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
                &lt;% end %&gt;
              &lt;/ul&gt;
            &lt;/div&gt;
          &lt;% end %&gt;
  
  
            &lt;%= text_field :user, :name, placeholder:'NAME', required: true %&gt;
            &lt;div style="position: relative;"&gt;
              &lt;span id="chk-username" style="position: absolute;font-size: 12px;right: 2%; bottom: 5%; z-index: 9; display: block;"&gt;&lt;/span&gt;
              &lt;%= text_field :user, :username, placeholder:'USERNAME', 'data-validate':"/users/check_username", required: true %&gt;
            &lt;/div&gt;
            &lt;div style="position: relative;"&gt;
              &lt;span id="chk-email" style="position: absolute;font-size: 12px;right: 2%; bottom: 5%; z-index: 9; display: block;"&gt;&lt;/span&gt;
              &lt;%= text_field :user, :email, placeholder:'EMAIL', 'data-validate':"/users/check_email", required: true %&gt;
            &lt;/div&gt;
            &lt;%= password_field :user, :password, placeholder:'PASSWORD', required: true %&gt;  
            &lt;%= password_field :user, :password_confirmation, placeholder:'CONFIRM PASSWORD', required: true %&gt; 
            &lt;div class="submit"&gt;
              &lt;input type="submit" value="REGISTER" &gt;
              &lt;input type="button" onclick="location.href = '&lt;%= request.base_url %&gt;/login'" value="LOGIN" &gt;
            &lt;/div&gt;    
            &lt;p&gt;&lt;a href="#"&gt;Forgot Password ?&lt;/a&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>user.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    #has_secure_password
  
    attr_accessor :password
    before_save :encrypt_password
  
    validates :name, presence: true
  
  
    validates :name, length: { minumum:2, maximum: 30 }
  
    validates :password, :presence =&gt;true,
      :length =&gt; { :minimum =&gt; 6, :maximum =&gt; 40 },
      :confirmation =&gt;true
  
    validates :username, :presence =&gt; true,
      :uniqueness =&gt; { :case_sensitive =&gt; false }
  
    email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    validates :email, :presence =&gt; true,
      :format =&gt; { :with =&gt; email_regex },
      :uniqueness =&gt; { :case_sensitive =&gt; false }
  
  
    def self.authenticate(input_username, input_password)
      user = find_by_username(input_username)
      if user &amp;&amp; user.password == BCrypt::Engine.hash_secret(input_password, user.password_salt)
        user
      else
        nil
      end
    end
  
    def encrypt_password
      if password.present?
        self.password_salt = BCrypt::Engine.generate_salt
        self.password = BCrypt::Engine.hash_secret(password, password_salt)
      end
    end
  end
  </code></pre>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>get    'register'   =&gt; 'users#register'
  post   'register'   =&gt; 'users#create_register'
  </code></pre>
  
  <p>Here is my database table.</p>
  
  <p><strong>users.sql (customize table)</strong></p>
  
  <pre><code>+----+----------+------------+-----------+----------------+
  | id | name     | username   |  password |  password_salt |
  +----+----------+------------+-----------+----------------+
  |  1 | chinmay  | chinu      | NULL      |$2a$10$15fWDt.. |
  |  2 | sanjib   | sanjib     | NULL      |$2a$10$85DyMr.. |
  +----+----------+------------+-----------+----------------+
  </code></pre>
  
  <p>I get <code>NULL</code> value in my <code>password</code> column. Please help me and let me know where the error is in my code.</p>