From de1086e9f4eae5e12b61de7bbdc208b472e04a69 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 24 Jun 2014 22:06:05 +0200 Subject: [PATCH] Updated readme with rake task to update existing users with OTP secret key --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 4db1e20..6992cf5 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,24 @@ The full path should be "app/views/devise/two_factor_authentication/show.html.er ``` +#### Updating existing users with OTP secret key + +If you have existing users that needs to be provided with a OTP secret key, so they can take benefit of the two factor authentication, create a rake. It could look like this one below: + +```ruby +desc "rake task to update users with otp secret key" +task :update_users_with_otp_secret_key => :environment do + users = User.all + + users.each do |user| + key = ROTP::Base32.random_base32 + user.update_attributes(:otp_secret_key => key) + user.save + puts "Rake[:update_users_with_otp_secret_key] => User '#{user.email}' OTP secret key set to '#{key}'" + end +end +``` + ### Example [TwoFactorAuthenticationExample](https://github.com/Houdini/TwoFactorAuthenticationExample)