List Info

Thread: restful_authentication: Where is 'crypted_password' ?




restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 11:22:13
Hi,

I'm using the latest version of RoR installed on Fedora Core
6 Linux
with Apache 2.2.  I just installed the plugin
"restful_authentication" (http://agilew
ebdevelopment.com/plugins/
restful_authentication), but whenever I try and create a new
user, via
this code:

        def userconfirm
                user = User.new(params[:user])    # line
59
                if user.save
                        flash[:notice] = 'User was
successfully
created.'
                        redirect_to :action => 'list'
                else
                        render :action => 'userinfo'
                end
        end

but I get this error.  Where do I find this
"crypted_password" method?
- Dave

 NameError in RegisterController#userconfirm

undefined local variable or method `crypted_password' for
#<User:
0xb766e3a8>

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1863:in `method_missing'
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:93:in
`password_required?'
/usr/local/apache2/htdocs/easyrx/app/controllers/
register_controller.rb:59:in `userconfirm'


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
country flaguser name
Germany
2008-01-21 11:39:43
that should be a column on the table users
-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 12:30:03
On Jan 21, 2008 12:22 PM, laredotornadozipmail.com
<laredotornadozipmail.com> wrote:
>
> Hi,
>
> I'm using the latest version of RoR installed on Fedora
Core 6 Linux
> with Apache 2.2.  I just installed the plugin
> "restful_authentication" (http://agilew
ebdevelopment.com/plugins/
> restful_authentication), but whenever I try and create
a new user, via
> this code:
>
>         def userconfirm
>                 user = User.new(params[:user])    # line
59
>                 if user.save
>                         flash[:notice] = 'User was
successfully
> created.'
>                         redirect_to :action =>
'list'
>                 else
>                         render :action =>
'userinfo'
>                 end
>         end
>
> but I get this error.  Where do I find this
"crypted_password" method?
> - Dave
>
>  NameError in RegisterController#userconfirm
>
> undefined local variable or method `crypted_password'
for #<User:
> 0xb766e3a8>
>
> RAILS_ROOT: ./script/../config/..
> Application Trace | Framework Trace | Full Trace
>
>
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
> active_record/base.rb:1863:in `method_missing'
>
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:93:in
> `password_required?'
> /usr/local/apache2/htdocs/easyrx/app/controllers/
> register_controller.rb:59:in `userconfirm'

If you ran the command

    script/generate authenticated user session

after installing the plugin, then it should have generated a
migration
which creates the users table with the necessary
attributes.

If you didn't and your Users table already exists, you can
generate
the rest of the stuff by using the --skip-migration option
on the
generate.

You can see the fields which are needed in this case by
looking in
vendor/plugins/restful_authentication/generators/authenticat
ed/templates/migration.rb


-- 
Rick DeNatale

My blog on Ruby
http://talklikead
uck.denhaven2.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 13:50:51
Ok, I added the column "crypted_password" to my
users table.  I assume
this means I should have deleted the column
"password".  Anyway, now I
get another warning when I try and create a user.  Upon
completing the
fields and entering a password and a confirmed password, I
get

There were problems with the following fields:
    * Password confirmation can't be blank

even though I'm entering a value for password confirmation. 
I don't
have a field "password_confirmation" in my
database ... didn't think I
needed one.  This is what the code looks like:

<p><label
for="user_login">Username</label><br/&
gt;
<%= text_field 'user', 'login'  %></p>

<p><label
for="user_password">Password</label><b
r/>
<%= password_field 'user', 'password'  %></p>

<p><label
for="password_confirmation">Confirm
Password</label><br/>
<%= password_field 'password_confirmation', '' 
%></p>

Any ideas? - Dave


On Jan 21, 11:39 am, Jimmy Palmer <rails-mailing-l...andreas-s.net>
wrote:
> that should be a column on the table users
> --
> Posted viahttp://www.ruby-forum.com
/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
country flaguser name
United States
2008-01-21 16:11:11

On Jan 21, 2008, at 2:50 PM, laredotornadozipmail.com wrote:

>
> Ok, I added the column "crypted_password" to
my users table.  I assume
> this means I should have deleted the column
"password".  Anyway, now I
> get another warning when I try and create a user.  Upon
completing the
> fields and entering a password and a confirmed
password, I get
>
> There were problems with the following fields:
>    * Password confirmation can't be blank
>
> even though I'm entering a value for password
confirmation.  I don't
> have a field "password_confirmation" in my
database ... didn't think I
> needed one.  This is what the code looks like:
>
> <p><label
for="user_login">Username</label><br/&
gt;
> <%= text_field 'user', 'login'  %></p>
>
> <p><label
for="user_password">Password</label><b
r/>
> <%= password_field 'user', 'password' 
%></p>
>
> <p><label
for="password_confirmation">Confirm
Password</label><br/>
> <%= password_field 'password_confirmation', '' 
%></p>
>
> Any ideas? - Dave
>
>
> On Jan 21, 11:39 am, Jimmy Palmer
<rails-mailing-l...andreas-s.net>
> wrote:
>> that should be a column on the table users
>>

You should have bits in your user model that look like these
(nearly  
all of it is pure generated code from
acts_as_authenticated):

   # Virtual attribute for the unencrypted password
   attr_accessor :password

   validates_presence_of     :login, :email
   validates_presence_of     :password,                  
:if  
=> :password_required?
   validates_presence_of     :password_confirmation,     
:if  
=> :password_required?
   validates_length_of       :password, :within => 4..40,
:if  
=> :password_required?
   validates_confirmation_of :password,                  
:if  
=> :password_required?
   validates_length_of       :login,    :within => 3..40
   validates_length_of       :email,    :within =>
3..100
   validates_uniqueness_of   :login, :email, :case_sensitive
=>  
false, :message => "has already been taken.  Please
choose another."

   before_save :encrypt_password

   # Authenticates a user by their email and unencrypted
password.   
Returns the user or nil.
   #
   # NOTE: This implicitly relies on the case-insensitive
string  
equality of
   # MySql when finding a matching email address.  If this
were to  
ever change,
   # the email should probably be made lowercase before
being saved  
(and before
   # doing the find, of course).
   def self.authenticate(email, password)
     u = find_by_email(email) # need to get the salt
     u && u.authenticated?(password) ? u : nil
   end

   def record_login_time
     update_attribute(:last_loggedin_at, Time.now.utc)
   end

   # Encrypts some data with the salt.
   def self.encrypt(password, salt)
    
Digest::SHA1.hexdigest("--#--#--")

   end

   # Encrypts the password with the user salt
   def encrypt(password)
     self.class.encrypt(password, salt)
   end

   def authenticated?(password)
     crypted_password == encrypt(password)
   end

   def remember_token?
     remember_token_expires_at && Time.now.utc < 

remember_token_expires_at
   end

   # These create and unset the fields required for
remembering users  
between browser closes
   def remember_me
     self.remember_token_expires_at = 2.weeks.from_now.utc
     self.remember_token            =
encrypt("#-- 
#")
     save(false)
   end

   def forget_me
     self.remember_token_expires_at = nil
     self.remember_token            = nil
     save(false)
   end

   protected

   # before save filter
   def encrypt_password
     return if password.blank?
     self.salt =
Digest::SHA1.hexdigest("--#{Time.now.to_s}-- 
#--") if new_record?
     self.crypted_password = encrypt(password)
   end

   # conditional validation
   def password_required?
     crypted_password.blank? || !password.blank?
   end

Pay particular attention to the conditional nature of the  
validations.  You only have to worry about the validation if
you do  
not yet have a crypted_password (i.e., already in the
database) or you  
have a non-blank password which typically means that the
user is in  
the midst of changing (or establishing) it.

NOTE: This is code that was extracted from a working model
in a real  
Rails project.  It does not necessarily work as is in YOUR
project and  
any difference between it and the code that the
acts_as_authenticated  
plugin produced is present for a reason (even if that reason
is just  
that I liked the indentation a bit better my way . YMMV

-Rob

Rob Biedenharn		http://agileconsultingl
lc.com
RobAgileConsultingLLC.com



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 16:33:02
<%= password_field 'password_confirmation', ''  %>;

should be

<%= password_field 'user&#39;, 'password_confirmation' %>



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: restful_authentication: Where is 'crypted_password' ?
country flaguser name
United States
2008-01-21 16:49:00
On Jan 21, 2008, at 5:33 PM, Ryan Bigg wrote:
<%= password_field 'password_confirmation', ''  %>;

should be

<%= password_field 'user', 'password_confirmation' %>

I think Ryan probably took better aim on this one.  I'm used to use form_for and not form_tag so my brain saw:
<%= f.password_field 'password_confirmation' %>
and filled in the rest!

But perhaps what I said helps someone else

-Rob

RobAgileConsultingLLC.com">RobAgileConsultingLLC.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Re: restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 17:59:34
Thanks.  This cured the problem.  On to the next one.  When
I create
the user, I now see an error:


 NoMethodError in RegisterController#userconfirm
undefined method `salt=' for #<User:0xb76961c8>
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1860:in `method_missing'
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:88:in
`encrypt_password'
/usr/local/apache2/htdocs/easyrx/app/controllers/
register_controller.rb:59:in `userconfirm'


How do I get salt defined?  Here is the code in my user.rb
file:

  protected
    # before filter
    def encrypt_password
      return if password.blank?
      self.salt =
Digest::SHA1.hexdigest("--#{Time.now.to_s}--
#--") if new_record?                      # line
88
      self.crypted_password = encrypt(password)
    end

and here is code from my register_controller.rb file:

        def userconfirm
                user = User.new(params[:user])
                if user.save         # line 59
                        flash[:notice] = 'User was
successfully
created.'
                        redirect_to :action => 'list'
                else
                        render :action => 'userinfo'
                end
        end



Thanks for your continued help, - Dave

On Jan 21, 4:33 pm, "Ryan Bigg"
<radarliste...gmail.com> wrote:
> <%= password_field 'password_confirmation', ''
 %>
>
> should be
>
> <%= password_field 'user', 'password_confirmation'
%>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: restful_authentication: Where is 'crypted_password' ?
user name
2008-01-21 18:02:53
Did you run script/generate authenticated account user? I'm beginning to think not.

salt is a required string field of your users table

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: restful_authentication: Where is 'crypted_password' ?
country flaguser name
United States
2008-01-21 18:16:48
On Jan 21, 2008, at 6:59 PM, laredotornadozipmail.com wrote:
> Thanks.  This cured the problem.  On to the next one. 
When I create
> the user, I now see an error:
>
> NoMethodError in RegisterController#userconfirm
> undefined method `salt=' for #<User:0xb76961c8>
> RAILS_ROOT: ./script/../config/..
> Application Trace | Framework Trace | Full Trace
>
>
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
> active_record/base.rb:1860:in `method_missing'
>
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:88:in
> `encrypt_password'
> /usr/local/apache2/htdocs/easyrx/app/controllers/
> register_controller.rb:59:in `userconfirm'
>
>
> How do I get salt defined?  Here is the code in my
user.rb file:

That should be a column in your database (and thus an
attribute of  
your user model).

-Rob
Rob Biedenharn		http://agileconsultingl
lc.com
RobAgileConsultingLLC.com

>
>  protected
>    # before filter
>    def encrypt_password
>      return if password.blank?
>      self.salt =
Digest::SHA1.hexdigest("--#{Time.now.to_s}--
> #--") if new_record?                      #
line 88
>      self.crypted_password = encrypt(password)
>    end
>
> and here is code from my register_controller.rb file:
>
>        def userconfirm
>                user = User.new(params[:user])
>                if user.save         # line 59
>                        flash[:notice] = 'User was
successfully
> created.'
>                        redirect_to :action =>
'list'
>                else
>                        render :action => 'userinfo'
>                end
>        end
>
>
>
> Thanks for your continued help, - Dave
>
> On Jan 21, 4:33 pm, "Ryan Bigg"
<radarliste...gmail.com> wrote:
>> <%= password_field 'password_confirmation', '' 
%>
>>
>> should be
>>
>> <%= password_field 'user',
'password_confirmation' %>




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-10]

about | contact  Other archives ( Real Estate discussion Medical topics )