Skip to content

Commit

Permalink
Intentionally break the user's password to invoke the invalid hash er…
Browse files Browse the repository at this point in the history
…ror so that the password can be reset (thanks to Devise changing password_salt)
  • Loading branch information
parndt committed Mar 27, 2011
1 parent 12f25d6 commit 0ab289c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion authentication/app/controllers/sessions_controller.rb
Expand Up @@ -5,7 +5,7 @@ class SessionsController < ::Devise::SessionsController

def create
super
rescue BCrypt::Errors::InvalidSalt
rescue ::BCrypt::Errors::InvalidSalt, ::BCrypt::Errors::InvalidHash
flash[:error] = t('password_encryption', :scope => 'users.forgot')
redirect_to new_user_password_path
end
Expand Down
@@ -1,6 +1,10 @@
class RemovePasswordSaltFromUsers < ActiveRecord::Migration
def self.up
remove_column :users, :password_salt
# Make the current password invalid :(
User.all.each do |u|
u.update_attribute(:encrypted_password, u.encrypted_password[29..-1])
end
end

def self.down
Expand Down
4 changes: 4 additions & 0 deletions db/migrate/20110325213325_remove_password_salt_from_users.rb
@@ -1,6 +1,10 @@
class RemovePasswordSaltFromUsers < ActiveRecord::Migration
def self.up
remove_column :users, :password_salt
# Make the current password invalid :(
User.all.each do |u|
u.update_attribute(:encrypted_password, u.encrypted_password[29..-1])
end
end

def self.down
Expand Down

0 comments on commit 0ab289c

Please sign in to comment.