diff --git a/db/migrate/20110727073510_change_crypted_password_length.rb b/db/migrate/20110727073510_change_crypted_password_length.rb index cdc1649c..9bd2c639 100644 --- a/db/migrate/20110727073510_change_crypted_password_length.rb +++ b/db/migrate/20110727073510_change_crypted_password_length.rb @@ -4,6 +4,17 @@ class ChangeCryptedPasswordLength < ActiveRecord::Migration end def self.down + # Begin with setting all passwords hashed with BCrypt to SHA-1 ones as + # BCrypt's format won't fit into a narrower column. + User.transaction do + User.all.each do |user| + if user.auth_type == 'database' and not user.uses_deprecated_password? + user.password = user.password_confirmation = nil + user.crypted_password = User.sha1 'change_me' + user.save! + end + end + end change_column 'users', 'crypted_password', :string, :limit => 40 end end