title: Validation failed: Password can't be blank
body: <p>I have an app, build on Rails 4.2 and tried to do twitter authentication, using <code>RailsCasts #241 Simple OmniAuth</code>.<br>
  But have this issue: <code>Validation failed: Password can't be blank!</code><br>
  I searched answer everywhere, but did not find the solution!</p>
  
  <p><strong>user.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
      has_secure_password
      validates :password, length: { minimum: 6 }, allow_blank: true
      def self.create_with_omniauth(auth)
          create! do |user|
              user.provider = auth.provider
              user.uid = auth.uid
              user.name = auth.info.name
          end
      end
  end
  </code></pre>
  
  <p><strong>sessions_controller.rb</strong>  </p>
  
  <pre><code>class SessionsController &lt; ApplicationController
     def login
     end
  
     def create
         @user = User.find_by_email(params[:email])
         if @user &amp;&amp; @user.authenticate(params[:password])
             session[:user_id] = @user.id
             redirect_to root_path
         else
             redirect_to :back
         end
     end
  
     def create_session
         auth = request.env['omniauth.auth']
         user = User.find_by_provider_and_uid(auth['provider'], auth['uid'])    || User.create_with_omniauth(auth)
         session[:user_id] = user.id
         redirect_to root_url, notice: 'Signed in!'
     end
  
     def logout
         reset_session
         redirect_to root_path
     end
  end
  </code></pre>
  
  <p><strong>routes.rb</strong>  </p>
  
  <pre><code>  get 'sessions/login'
    get 'sessions/logout'
    post 'sessions' =&gt; 'sessions#create'
  
    get '/auth/:provider/callback' =&gt; 'sessions#create_session'
    post '/auth/:provider/callback' =&gt; 'sessions#create_session'
  
    get 'registration' =&gt; 'users#new', as: 'registration'
  </code></pre>
  
  <p><strong>Solution</strong><br>
  After editing <strong>user.rb</strong> model looks like:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
      has_secure_password
      validates :password, length: { minimum: 6 }
      require 'securerandom'
      def self.create_with_omniauth(auth)
         create! do |user|
            user.provider = auth.provider
            user.uid = auth.uid
            user.name = auth.info.name
            user.password = SecureRandom.urlsafe_base64
         end
      end
  end
  </code></pre>