Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:49:39+00:00 2026-05-27T23:49:39+00:00

I’m updating a database hashing algorithm. My current system runs on md5 and I

  • 0

I’m updating a database hashing algorithm.

My current system runs on md5 and I want to change it into BCrypt +salt.

My problem is when an old user(users whos password hashed in md5) is login with his old password I want to automatically change the password to BCrypt+salt in database.

       if // check if the password stored in bcrypt
        salt = IDA::Config.get_configuration('salt')
        hash_password = BCrypt::Password.new(hash)
         return (BCrypt::Password.create(salt['salt_value']+password) == (salt['salt_value']+password)) ? true : false

      else // for users who's password encrypted in md5.

        salt = IDA::Config.get_configuration('salt') // i"m getting a salt here 
         BCrypt::Password.create(salt['salt_value']+password) // Im getting a salted bcryptted password  and I tried to put this into db manually and try to login it works perfectly
          // I want to write this new salted password into db once the user is authenticated with his old password
        return (Digest::MD5.hexdigest(password) == hash) ? true : false

I want to write this in model.Any help will be greatly appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:49:40+00:00Added an answer on May 27, 2026 at 11:49 pm

    First off, BCrypt (both the library and the gem) handles salt so you can nix all of the salt business.

    Second what you really want is a way of re-hashing all of your records sensitive data (passwords I assume). So here’s what you do:

    1. Add a field to the model, something like “is_bcrypt?” and boolean.
    2. Write and run this:

    # First we need to make sure the bcrypt library is there
    require 'bcrypt'
    
    # Gather all of the records
    records = YourModel.all
    
    # Go over each of the records
    records.each do |record|
      # Check to see if the record has a bcrypt'ed password
      unless record.is_bcrypt?
        # If it doesn't take the value of password, unhash it, rehash it
        record.password = BCrypt::Password.create Digest::MD5.hexdigest password
    
        # If it saves correctly, mark the thing as being rehashed
        record.is_bcrypt = true if record.save
      end
    end
    

    See comments for details. The new field is_bcrypt is just so you can know which records have been hashed and which haven’t. It only happens if they actually save too.

    When this is done, and you’re sure all the code concerning passwords is refactored you can take out that field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.