Note that there are some explanatory texts on larger screens.

plurals
  1. POReset Password Validation Error: Password is too short error even though password is within range
    primarykey
    data
    text
    <p>Recently, I changed my code for password validation to the code below so that I could create a form that doesn't require password and password confirmation <a href="https://stackoverflow.com/questions/10566865/how-to-only-change-one-attribute-in-a-model-using-form-for-in-rails">How to only change one attribute in a model using form_for in Rails</a>.</p> <p>Please note that I did not user has_secure_password to generate my encrypted password. I used SHA2.hexdigest per Hartl in RailsTutorial.</p> <p>user.rb</p> <pre><code>before_save :encrypt_password, :unless =&gt; Proc.new { |u| u.password.blank? } validates_presence_of :password, :if =&gt; :should_validate_password? validates_confirmation_of :password, :if =&gt; :should_validate_password? validates_length_of :password, :minimum =&gt; 6, :maximum =&gt; 40, :allow_blank =&gt; true #changing :allow_blank from false to true above fixed my problem. def should_validate_password? updating_password || new_record? end </code></pre> <p>I followed this Railscast on Remember Me/Reset Password <a href="http://railscasts.com/episodes/274-remember-me-reset-password" rel="nofollow noreferrer">http://railscasts.com/episodes/274-remember-me-reset-password</a>, and I keep getting this error:</p> <p><strong><code>ActiveRecord::RecordInvalid in PasswordResetsController#create</code></strong></p> <p><strong><code>Validation failed: Password is too short (minimum is 6 characters)</code></strong></p> <p>This occured when I tried to generate auth_tokens for existing users and again when I tried to submit my email for a reset link. I was able temporarily remove this validation by commenting out the piece of code and everything worked fine.</p> <p>I tried signing back in to the user account to change the password so that it was within the range (9 characters long), but I'm still getting the same length validation error message.</p> <p>Any tips?</p> <p>I have no idea where the problem stems from. I don't understand why my password is being validated.</p> <p>Here is my create action in my Password Resets controller:</p> <pre><code>def create user = User.find_by_email(params[:email]) user.send_password_reset if user redirect_to root_path, :notice =&gt; "Email sent with password reset" end </code></pre> <p>Here is my password reset form:</p> <pre><code>&lt;%= form_tag password_resets_path, :method =&gt; :post do %&gt; &lt;div class="field"&gt; &lt;%= label_tag :email %&gt; &lt;%= text_field_tag :email, params[:email] %&gt; &lt;/div&gt; &lt;div class="actions"&gt;&lt;%= submit_tag "Reset Password" %&gt;&lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Let me know if you guys need any additional files.</p> <p>Edit: Made changes in code with working solution.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload