# password validation

**URL:** <https://discuss.rubyonrails.org/t/password-validation/9055>\
**Category:** rubyonrails-talk\
**Created:** [February 20, 2007, 10:26pm UTC](https://discuss.rubyonrails.org/t/password-validation/9055 "2007-02-20T22:26:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh2](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@Josh2](https://discuss.rubyonrails.org/u/Josh2)\
**Post date:** [February 20, 2007, 10:26pm UTC](https://discuss.rubyonrails.org/t/password-validation/9055/1 "2007-02-20T22:26:30Z")

</div>

i'm using the authentication chapter in the rails recipes book to help me out, but i ran into a snag...

it uses password\_hash and password\_salt as the fields for storing the database info. but in the model, there is a password=(pass) method that does the work for generating the salt and the encryption.

since "password" isn't one of the database fields, i'm having validation problems. i have a 'validates\_presence\_of' for the password method which works fine, but my problem comes when i am updating a User record that doesn't have a password field in the form. i am still getting the "password can't be blank" error.

what's the best workaround for this so i can only use the validations on "password" when i am updating the password.

i hope that makes sense...

---

<div class="post-metadata">

**Author:** ![Kim](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@Kim](https://discuss.rubyonrails.org/u/Kim)\
**Post date:** [February 20, 2007, 10:43pm UTC](https://discuss.rubyonrails.org/t/password-validation/9055/2 "2007-02-20T22:43:32Z")

</div>

This is a great article: [http://www.aidanf.net/rails\_user\_authentication\_tutorial](http://www.aidanf.net/rails_user_authentication_tutorial) It does authentications like the rails recipe but it explains the validation process for password.

I implemented authentication by following this article and it worked great.

Hope that helps - K

---

<div class="post-metadata">

**Author:** ![Josh2](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@Josh2](https://discuss.rubyonrails.org/u/Josh2)\
**Post date:** [February 21, 2007, 1:22am UTC](https://discuss.rubyonrails.org/t/password-validation/9055/3 "2007-02-21T01:22:14Z")

</div>

actually that did help out alot. i didn't find the answer i was looking for in the article, but someone had the same problem as i did in the comments and posted their solution. they just wanted validation to work if there was a password field in the form, like if they wanted to change just their name or email address.

they put this in their model:

&nbsp;&nbsp;validates\_presence\_of :password, :if =\> :password\_required?

and further down had something like this:

&nbsp;&nbsp;protected &nbsp;&nbsp;def password\_required? &nbsp;&nbsp;&nbsp;&nbsp;!password.nil? &nbsp;&nbsp;end

i think i read that this is similar to the way that mephisto works.
