4

In my app I need to have a database authentication but without a password. Just by entering your phone number. When the user sings up he enter phone number, adress and name and no password.

Is it real? Just can't figure out how to make it.

Thanks for help in advance!

nxxn
  • 329
  • 3
  • 14
  • 1
    Authentication is generally achieved by asking the user that something only they know, or prove they are in possession of something unique to them. A phone number on its own doesn't fulfill this - but if it was a mobile number, you could maybe send an SMS message with a code they must use to confirm they have the phone? – Paul Dixon Oct 25 '11 at 11:47
  • Windows Authentication or similar? – leppie Oct 25 '11 at 11:49

1 Answers1

9

Figured out like this:

In devise_no_pass.rb initializer add:

require 'devise/strategies/authenticatable'

module Devise
  module Strategies
    class DeviseNoPass < Authenticatable
      def authenticate!
        return super unless params[:customer_sign_in]
        customer = Customer.find_by_phone(params[:customer_sign_in]
        customer ? success!(customer) : raise
      end
    end
  end
end

Warden::Strategies.add(:devise_no_pass, Devise::Strategies::DeviseNoPass)

In devise.rb:

    config.warden do |manager|
      manager.default_strategies(:scope => :customer).unshift :devise_no_pass
    end
Denis
  • 143
  • 1
  • 6
nxxn
  • 329
  • 3
  • 14
  • Can you share your Customer model code in relation to devise... and routes for this, as well as your login form? I'm trying to do something similar and it would be helpful. I'd like to see what devise modules you enabled in the model specifically – Joel Grannas Apr 30 '14 at 23:06
  • I'm sorry, but I haven't got this project code anymore. And I can't remember what exactly there was from my head. – nxxn May 04 '14 at 16:28
  • Hey, I am also working on the same problem but no luck yet. I need to login without password i.e login with only username.@Joel did you find the solution ? – Ankit Tyagi May 20 '14 at 07:53