From e62e68e25bb7b1281e20e228db66f7deace4330f Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 8 Jul 2018 13:56:07 +0300 Subject: has_secure_password: use `recovery_password` instead of `activation_token` Since we have `has_secure_token`, it is too confusing to use `_token` suffix with `has_secure_password`. Context https://github.com/rails/rails/pull/33307#discussion_r200807185 --- guides/source/active_model_basics.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'guides') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index bad3543924..09b4782eca 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -466,7 +466,7 @@ a `password` accessor with certain validations on it by default. `ActiveModel::SecurePassword` depends on [`bcrypt`](https://github.com/codahale/bcrypt-ruby 'BCrypt'), so include this gem in your `Gemfile` to use `ActiveModel::SecurePassword` correctly. In order to make this work, the model must have an accessor named `XXX_digest`. -Where `XXX` is the attribute name of your desired password/token or defaults to `password`. +Where `XXX` is the attribute name of your desired password. The following validations are added automatically: 1. Password should be present. @@ -479,9 +479,9 @@ The following validations are added automatically: class Person include ActiveModel::SecurePassword has_secure_password - has_secure_password :activation_token, validations: false + has_secure_password :recovery_password, validations: false - attr_accessor :password_digest, :activation_token_digest + attr_accessor :password_digest, :recovery_password_digest end person = Person.new @@ -506,16 +506,16 @@ person.valid? # => true person.password = person.password_confirmation = 'aditya' person.valid? # => true -person.activation_token = "a_new_token" +person.recovery_password = "42password" person.authenticate('aditya') # => person person.authenticate('notright') # => false person.authenticate_password('aditya') # => person person.authenticate_password('notright') # => false -person.authenticate_activation_token('a_new_token') # => person -person.authenticate_activation_token('notright') # => false +person.authenticate_recovery_password('42password') # => person +person.authenticate_recovery_password('notright') # => false -person.password_digest # => "$2a$04$l4yYxoUPibMXcvvu.Lq8M.T/rtjdLOA78LN2XHEzMovf7hWVGzgXC" -person.activation_token_digest # => "$2a$10$0Budk0Fi/k2CDm2PEwa3BeXO5tPOA85b6xazE9rp8nF2MIJlsUik." +person.password_digest # => "$2a$04$gF8RfZdoXHvyTjHhiU4ZsO.kQqV9oonYZu31PRE4hLQn3xM2qkpIy" +person.recovery_password_digest # => "$2a$04$iOfhwahFymCs5weB3BNH/uXkTG65HR.qpW.bNhEjFP3ftli3o5DQC" ``` -- cgit v1.2.3