# Validating passwords

**URL:** <https://www.ruby-forum.com/t/validating-passwords/88273>\
**Category:** Rails\
**Created:** [March 9, 2007, 10:29am UTC](https://www.ruby-forum.com/t/validating-passwords/88273 "2007-03-09T10:29:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 9, 2007, 10:29am UTC](https://www.ruby-forum.com/t/validating-passwords/88273/1 "2007-03-09T10:29:12Z")

</div>

Hey people,

I was wondering how to solve the following problem…

I have a login system which uses MD5 + salts to store my users passwords  
in the database. Also I am working with profiles for my users which they  
can change.

Everything goes quite okay except when we reach the change\_profile bit  
of the application. Because the user model has validations it performs  
on the password it starts throwing error when a user views the  
change\_profile page. The errors are there as soon as the page is loaded,  
even before the form gets submitted.

3 errors prohibited this candidate from being saved

There were problems with the following fields:

```
* Password confirmation can't be blank
* Password can't be blank
* Password is too short (minimum is 4 characters)

```

Is there a way to stop the model from using it’s password validations  
whenever a user is changing his profile? I tried to exclude the password  
fields from the change\_profile form, but this still generates the same  
errors…

Thanks in advance,

Danny

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 9, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/validating-passwords/88273/2 "2007-03-09T14:58:08Z")

</div>

Hi Danny,

Daniel Owen van Dommelen wrote:

> Because the user model has validations it performs  
> on the password it starts throwing error when a user  
> views the change\_profile page. The errors are there  
> as soon as the page is loaded, even before the form  
> gets submitted.
> 
> 3 errors prohibited this candidate from being saved
> 
> Is there a way to stop the model from using it’s password  
> validations whenever a user is changing his profile?

Sorry to be dense, but I’m not getting a clear picture here and need to  
ask  
a couple of questions. Is the password stored in the User model? Is  
the  
profile part of the User model? Validations get run on three events:  
create, update, and save. You must be doing one of those to get the  
errors  
you’re getting. Which doesn’t make sense given your description of the  
situation. Or maybe I just haven’t gotten enough caffine into the  
system  
yet 😉 At any rate, you can specify which event(s) trigger the  
validation(s) in your validate methods. Check the  
ActiveRecord::Validations::ClassMethods documentation at  
[http://api.rubyonrails.org/](http://api.rubyonrails.org/)

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [March 9, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/validating-passwords/88273/3 "2007-03-09T15:31:13Z")

</div>

Bill W. wrote:

> Hi Danny,
> 
> Daniel Owen van Dommelen wrote:
> 
> > Because the user model has validations it performs  
> > on the password it starts throwing error when a user  
> > views the change\_profile page. The errors are there  
> > as soon as the page is loaded, even before the form  
> > gets submitted.
> > 
> > 3 errors prohibited this candidate from being saved
> > 
> > Is there a way to stop the model from using it’s password  
> > validations whenever a user is changing his profile?
> 
> Sorry to be dense, but I’m not getting a clear picture here and need to  
> ask  
> a couple of questions. Is the password stored in the User model? Is  
> the  
> profile part of the User model? Validations get run on three events:  
> create, update, and save. You must be doing one of those to get the  
> errors  
> you’re getting. Which doesn’t make sense given your description of the  
> situation. Or maybe I just haven’t gotten enough caffine into the  
> system  
> yet 😉 At any rate, you can specify which event(s) trigger the  
> validation(s) in your validate methods. Check the  
> ActiveRecord::Validations::ClassMethods documentation at  
> [http://api.rubyonrails.org/](http://api.rubyonrails.org/)
> 
> hth,  
> Bill

Hey, thanks for replying… I believe one of the members on our team has  
already resolved the problem. The problem was pretty complex and at the  
moment I just do not have the time to completely detail it for you…  
Anyways, thanks again for replying, you’ll probably see me back here 😉

Ow and about the coffee, I guess that must be one of the reasons for  
basically everything, goigng to “the machine” right now myself…
