Validations over hashed password

I have this method in user.rb that automatically converts password to
SHA1 hash

def password=(value)
    write_attribute("password", Digest::SHA1.hexdigest(value))
end

but my user model validations dont seem to work properly…for example
length_of and confirmation_of… cause it gets SHA1 and stuff…

how do I keep it encrypted yet keep validations too?

if I remove the above mentioned method, it works fine but I risk the
password being naked :confused: