mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-28 04:00:45 +00:00
Update more reasonable/helpful scrypt migration
This commit is contained in:
parent
c3ceb7853d
commit
4da3f38d25
2 changed files with 7 additions and 1 deletions
|
@ -3,6 +3,9 @@
|
||||||
# Development-specific ENV variables, loaded after .env and before .env*local
|
# Development-specific ENV variables, loaded after .env and before .env*local
|
||||||
# Add changes only specific to dev. env.
|
# Add changes only specific to dev. env.
|
||||||
|
|
||||||
|
# Scrypt max time
|
||||||
|
SCRYPT_MAX_TIME=0.005
|
||||||
|
|
||||||
# These are
|
# These are
|
||||||
RACK_ENV=development
|
RACK_ENV=development
|
||||||
RAILS_ENV=development
|
RAILS_ENV=development
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
|
||||||
ENV['SCRYPT_MAX_TIME'] ||= "0.03"
|
ENV['SCRYPT_MAX_TIME'] ||= "1"
|
||||||
class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
|
class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
|
||||||
require 'scrypt'
|
require 'scrypt'
|
||||||
|
|
||||||
def up
|
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)
|
SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME'].to_f)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
User.all.order(:id).each do |user|
|
User.all.order(:id).each do |user|
|
||||||
|
@ -11,6 +13,7 @@ class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
|
||||||
if user.valid?
|
if user.valid?
|
||||||
user.update_password
|
user.update_password
|
||||||
user.save!
|
user.save!
|
||||||
|
puts("User %s (%d) updated" % [user.username, user.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue