Custom devise strategy without password

1,146 views
Skip to first unread message

Nikita Gnotovs

unread,
Oct 25, 2011, 7:40:44 AM10/25/11
to Devise
Hello,

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!

naveed tariq

unread,
Oct 25, 2011, 8:36:20 AM10/25/11
to plataforma...@googlegroups.com
If you really need to have this functionality then you can over-ride the function password_required? in your model like this

def password_required?
    false
end

Regards

Nikita Gnotovs

unread,
Oct 27, 2011, 8:02:44 AM10/27/11
to Devise
Thanks, that helped me to sign_up user without a password, but I
can't sign_in without a password. Any advices will be helpful.

Regards

naveed tariq

unread,
Oct 27, 2011, 8:06:57 AM10/27/11
to plataforma...@googlegroups.com
Hi

If you can let me know the flow of registration and log in may be the I can help you better.

Regards

2011/10/27 Nikita Gnotovs <n.gn...@gmail.com>

naveed tariq

unread,
Oct 27, 2011, 8:12:57 AM10/27/11
to plataforma...@googlegroups.com
There are a couple of hacks you do achieve this task although i am not sure why would require such a case where you need authentication but without a password.

One is to set a password manually to some default password and then passing a hidden field naming password with the default value. But thats not a good way.

The other option is you over-ride valid_password? method which always return true. I haven't tried this method as yet but I think it will work.

Regards

2011/10/27 naveed tariq <naved...@gmail.com>

Nikita Gnotovs

unread,
Oct 27, 2011, 8:52:35 AM10/27/11
to Devise
The flow of registration and log in:

User sign_up a account, where he leaves his name,surname, phone,
adress. And sign_in should be just be entering a phone number.

What should I with valid_password? ?

Regards

On 27 окт, 15:12, naveed tariq <naved.ta...@gmail.com> wrote:
> There are a couple of hacks you do achieve this task although i am not sure
> why would require such a case where you need authentication but without a
> password.
>
> One is to set a password manually to some default password and then passing
> a hidden field naming password with the default value. But thats not a good
> way.
>
> The other option is you over-ride valid_password? method which always return
> true. I haven't tried this method as yet but I think it will work.
>
> Regards
>
> 2011/10/27 naveed tariq <naved.ta...@gmail.com>
>
>
>
>
>
>
>
> > Hi
>
> > If you can let me know the flow of registration and log in may be the I can
> > help you better.
>
> > Regards
>
> > 2011/10/27 Nikita Gnotovs <n.gno...@gmail.com>

naveed tariq

unread,
Oct 27, 2011, 9:20:56 AM10/27/11
to plataforma...@googlegroups.com
just try to over-ride it in your model to return true everytime and check if you get the functionality you want?



2011/10/27 Nikita Gnotovs <n.gn...@gmail.com>

Nikita Gnotovs

unread,
Oct 27, 2011, 9:29:04 AM10/27/11
to Devise
For now i have

def valid_password?
true
end

in my model. But it doesnt help.



On 27 окт, 16:20, naveed tariq <naved.ta...@gmail.com> wrote:
> just try to over-ride it in your model to return true everytime and check if
> you get the functionality you want?
>
> 2011/10/27 Nikita Gnotovs <n.gno...@gmail.com>

naveed tariq

unread,
Oct 27, 2011, 9:36:17 AM10/27/11
to plataforma...@googlegroups.com
Then you can try the other option i specified to have a fixed password and passing it as a hidden field from the form. meanwhile i try to find another elegant solution to the problem.

2011/10/27 Nikita Gnotovs <n.gn...@gmail.com>

Nikita Gnotovs

unread,
Oct 27, 2011, 9:39:49 AM10/27/11
to Devise
Thanks a lot. I'll try to find some solution too. Just because hidden
field is not so elegant.

On 27 окт, 16:36, naveed tariq <naved.ta...@gmail.com> wrote:
> Then you can try the other option i specified to have a fixed password and
> passing it as a hidden field from the form. meanwhile i try to find another
> elegant solution to the problem.
>
> 2011/10/27 Nikita Gnotovs <n.gno...@gmail.com>

Nikita Gnotovs

unread,
Oct 27, 2011, 5:27:42 PM10/27/11
to Devise
For now I made my own strategy, but it doesnt help.

require 'devise/strategies/authenticatable'

module Devise
module Strategies
class DeviseNoPass < Authenticatable
def valid?
true
end
puts "TEST"
def authenticate!
customer = Customer.find_by_phone(params[:phone])
if customer == params[:phone]
success!(customer)
else
fail
end
end
end
end
end

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

On 27 окт, 16:36, naveed tariq <naved.ta...@gmail.com> wrote:
> Then you can try the other option i specified to have a fixed password and
> passing it as a hidden field from the form. meanwhile i try to find another
> elegant solution to the problem.
>
> 2011/10/27 Nikita Gnotovs <n.gno...@gmail.com>

Jeffrey Jones

unread,
Oct 27, 2011, 8:13:14 PM10/27/11
to plataforma...@googlegroups.com
I havent gone through all the replies in this thread but I wrote a
strategy that might work for you called called devise-gullible. Might be
worth a look.

https://github.com/toppan-forms/devise-gullible

Nikita Gnotovs

unread,
Oct 28, 2011, 4:58:35 PM10/28/11
to Devise
I've copied lib folder from your git to my app. But seems like I'm
doing something wrong, because it's not working. Can you please help
me, what I need to copy to my app?

Jeffrey Jones

unread,
Oct 30, 2011, 8:18:00 PM10/30/11
to plataforma...@googlegroups.com
You need to copy the entire directory, not just the lib one if you want
it to work in a rails appication.

You also need to make sure that /lib is in your loadpath since it might
not be depending on your rails version.

Another (better) option is to clone the repository, create a local gem
(using the included rake task) and the install that gem using gem
install --local.
I never created a gem on rubygems because of the lack of tests.

Reply all
Reply to author
Forward
0 new messages