Question: My Rails 5 App only permits an admin or support user to create a user, when the user is created a password is generated and emailed to the user, on the first user login the app forces them to change the password. 

I have a password\_updated field in my schema that I want to be filled to true when the password is updated, however I am hitting a wall here, not sure if its coder eye and I just cant see what where im going wrong. 

my application controller: 

```
  # Force User To Change Password On First Login
  def after_sign_in_path_for(resource)
    if current_user.password_updated == "false"
      edit_passwords_path
    else
      authenticated_root_path
    end
  end

```

I have it set up so that if the user tries to skip or jump past the password change they are redirected to the password change. 

my passwords controller: 

```
class PasswordsController < ApplicationController
  def edit
    @user = current_user
  end

  def update
    if current_user.update_with_password(user_params)
      current_user.password_updated = "true"
      flash[:notice] = 'Your Password Has Been Sucessfully Updated.'
      redirect_to authenticated_root_path
    else
      flash[:error] = 'Oh No! Something Went Wrong, Please Try Again.'
      render :edit
    end
  end

  private
    def user_params
      params.require(:user).permit(:password_updated, :current_password, :password, :password_confirmation)
    end

end

```

Originally I had the application controller looking at the sign in count, however if the user closed out and waited long enough they could log back in and not have to change the password. I felt this was more of a risk. 

Any assistance here would be greatly appreciated.

Answer: 
Since this is One-time task. Fastest way is to load whole file into memory, scan memory line by line, parse key and compare it with search key(keys) and print(save) found positions.

UPD: If you have sorted list in source file. And assume you have 411000keys to lookup. You can use this trick: Sort you search keys in same order with source file. Read first key from both lists and compare it. If they differs read next from source until they equal. Save position, if next key in source also equal, save it too..etc. If next key is differ, read next key from search keys list. Continue until EOF.
Use memory-mapped files. Just think your file is already read into the memory in its entirety and do that very binary search in memory that you wanted. Let Windows care about reading the portions of file when you do your in-memory search.

* <https://en.wikipedia.org/wiki/Memory-mapped_file>
* <https://msdn.microsoft.com/en-us/library/ms810613.aspx>
* <https://stackoverflow.com/a/9609448/976391>
* <https://stackoverflow.com/a/726527/976391>
* <http://msdn.microsoft.com/en-us/library/aa366761%28VS.85.aspx>
* <https://msdn.microsoft.com/en-us/library/windows/desktop/aa366537.aspx>

You may take any of those sources for start, just do not forget to update them for Win64

<http://torry.net/quicksearchd.php?String=memory+mapped+files&Title=No>