# Validation on password attr\_accessor

**URL:** <https://www.ruby-forum.com/t/validation-on-password-attr-accessor/162121>\
**Category:** Rails\
**Created:** [March 5, 2009, 11:03pm UTC](https://www.ruby-forum.com/t/validation-on-password-attr-accessor/162121 "2009-03-05T23:03:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![r-a-mueller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/dfb087/32.png) [@r-a-mueller](https://www.ruby-forum.com/u/r-a-mueller)\
**Post date:** [March 5, 2009, 11:03pm UTC](https://www.ruby-forum.com/t/validation-on-password-attr-accessor/162121/1 "2009-03-05T23:03:54Z")

</div>

I am using the authentication example of Rails Recipes book (around  
page 135)

I am trying to make a sign-up form for it

I have the following method

def password=(pass)  
salt=[Array.new(6){rand(256).chr}.join].pack(“m”).chomp  
self.password\_salt, self.password\_hash = salt,  
Digest::SHA256.hexdigest(pass + salt)  
end

which seems to work

I use

attr\_accessor :password

So that I can have a password field on my form

But if I use validates\_length\_of :password, :within =\> 5…40

The password always fails the validation even if I enter more that 5  
chars etc…

Any help would be appreciatted

Thanks

Richard  
Japan
