From 4da3f38d2590f1d29cac8c7603cb6ad660d6437c Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Mon, 6 Apr 2020 05:50:30 +0300 Subject: [PATCH] Update more reasonable/helpful scrypt migration --- .env.development | 3 +++ db/migrate/20200401031518_update_passwords_to_scrypt.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index d16656e..111169e 100644 --- a/.env.development +++ b/.env.development @@ -3,6 +3,9 @@ # Development-specific ENV variables, loaded after .env and before .env*local # Add changes only specific to dev. env. +# Scrypt max time +SCRYPT_MAX_TIME=0.005 + # These are RACK_ENV=development RAILS_ENV=development diff --git a/db/migrate/20200401031518_update_passwords_to_scrypt.rb b/db/migrate/20200401031518_update_passwords_to_scrypt.rb index 531f7ba..86e49ad 100644 --- a/db/migrate/20200401031518_update_passwords_to_scrypt.rb +++ b/db/migrate/20200401031518_update_passwords_to_scrypt.rb @@ -1,9 +1,11 @@ -ENV['SCRYPT_MAX_TIME'] ||= "0.03" +ENV['SCRYPT_MAX_TIME'] ||= "1" class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0] require 'scrypt' def up + puts("SCRYPT_MAX_TIME=%s" % ENV['SCRYPT_MAX_TIME']) + puts("Migration takes about %0.0f seconds." % ENV['SCRYPT_MAX_TIME'].to_f*User.all.count) SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME'].to_f) ActiveRecord::Base.transaction do User.all.order(:id).each do |user| @@ -11,6 +13,7 @@ class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0] if user.valid? user.update_password user.save! + puts("User %s (%d) updated" % [user.username, user.id]) end end end