Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Last active August 29, 2015 14:19
Show Gist options
  • Save oojikoo-gist/3d2573cd34637b268a72 to your computer and use it in GitHub Desktop.
Save oojikoo-gist/3d2573cd34637b268a72 to your computer and use it in GitHub Desktop.
rails: devise security
# /config/initializers/devise.rb
config.password_length = 8..128
# user model validates
validate :password_complexity
def password_complexity
if password.present? and not password.match(/\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+\z/)
errors.add :password, "must include at least one lowercase letter, one uppercase letter, and one digit"
end
end
# /config/initializers/devise.rb
config.stretches = Rails.env.test? ? 1 : 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment