ruby on rails - How can I perform password complexity validation on devise without having to install other gems? -


i using devise authentication in rails app. want add validation password complexity rules. seems don't have access raw password @ model level before has been hashed. such, cannot validate raw password provided conforms password complexity rules have set. other way can @ controller-level. however, i'm afraid that approach pollute controller. ideas how can perform validation without having install other gem?

here simple method of adding password strength / complexity requirement @ model level.

#app/models/user.rb  validate :password_complexity  def password_complexity   if password.present?      if !password.match(/^(?=.*[a-z])(?=.*[a-z])/)         errors.add :password, "password complexity requirement not met"      end   end end 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -