# Problem with the Authorization recipe

**URL:** <https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401>\
**Category:** Rails\
**Created:** [April 21, 2006, 6:57am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401 "2006-04-21T06:57:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anabia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@anabia](https://www.ruby-forum.com/u/anabia)\
**Post date:** [April 21, 2006, 6:57am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401/1 "2006-04-21T06:57:05Z")

</div>

I just got the rails recipes book and i couldnt be more happy, but  
inside the book there are some details, mostly typos but this one its  
one i cant fix, im following the Authorization recipe on page 128 i  
create the table and the model, the problem comes when i try to assign a  
password to a user in the console, here is the output:

> > justin = User.create(:username =\> “justin”)  
> > =\> #\<User:0x3c9cd38 @errors=#\<ActiveRecord::Errors:0x3c9b730 @errors={},  
> > @base=#\<User:0x3c9cd38 …\>\>, @attributes={“password\_salt”=\>nil,  
> > “username”=\>“justin”, “id”=\>4, “password\_hash”=\>nil}, @new\_record=false\>
> 
> > justin.password = “secret”  
> > NameError: uninitialized constant Digest::SHA2  
> > from  
> > c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active\_support/dependencies.rb:89:in  
> > `const_missing' from ./script/../config/../config/../app/models/user.rb:5:in`password=’  
> > from (irb):4
> 
> >

and here are my model:

class User \< ActiveRecord::Base  
validates\_uniqueness\_of :username  
def password=(pass)  
salt = [Array.new(6){rand(256).chr}.join].pack(“m”).chomp  
self.password\_salt, self.password\_hash = salt,  
Digest::SHA256.hexidigest(pass + salt)  
end  
end

Its clearly seems to be a problem of the SHA2 library but searching  
around i cant find any reasonable info that helps to fix this problem,  
hope someone can give me a hand with this 🙂

---

<div class="post-metadata">

**Author:** ![anabia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@anabia](https://www.ruby-forum.com/u/anabia)\
**Post date:** [April 21, 2006, 7:28am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401/2 "2006-04-21T07:28:02Z")

</div>

## You required digest/sha2 right?

View this message in context:  
[http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608](http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![anabia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@anabia](https://www.ruby-forum.com/u/anabia)\
**Post date:** [April 21, 2006, 7:52am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401/3 "2006-04-21T07:52:43Z")

</div>

Typo - it should be ‘hexdigest’, not ‘hexidigest’

---

<div class="post-metadata">

**Author:** ![anabia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@anabia](https://www.ruby-forum.com/u/anabia)\
**Post date:** [April 21, 2006, 7:46am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401/4 "2006-04-21T07:46:01Z")

</div>

Steve R. wrote:

> ## You required digest/sha2 right?
> 
> View this message in context:  
> [http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608](http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608)  
> Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

ok, dumb mistakenow i required sha2: require ‘digest/sha2’ but the  
problems keep coming, now i get this when trying to assign a password:

> > negro3.password = “secret”  
> > NoMethodError: undefined method `hexidigest' for Digest::SHA256:Class from ./script/../config/../config/../app/models/user.rb:6:in `password=’  
> > from (irb):3

Im using windows/rails1.1/ruby1.8.4 even in the forums of the recipes  
book i cant find a good answer to fix this.

---

<div class="post-metadata">

**Author:** ![anabia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@anabia](https://www.ruby-forum.com/u/anabia)\
**Post date:** [April 21, 2006, 8:00am UTC](https://www.ruby-forum.com/t/problem-with-the-authorization-recipe/58401/5 "2006-04-21T08:00:20Z")

</div>

David M. wrote:

> Typo - it should be ‘hexdigest’, not ‘hexidigest’

oh noÂ¡ no no no, i have 3 hours working in how to fix this problem, all  
was a simple thing, that typo.

Thanks so much for your help guys, really 😉
