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

  • Home
  • SEARCH
  • 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 8306021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:14:48+00:00 2026-06-08T18:14:48+00:00

i have a problem. i am a rookie programmer, about a year ago i

  • 0

i have a problem.

i am a rookie programmer, about a year ago i started learning php by myself to write an application.

like all rookies i made some big mistakes that i realized after the application was launched.

things like missing foreign keys un-encrypted cookie stored password….and stuff like that.

now before you judge me i got the application to work and i wasnt anticipating the application to well, and was expecting well below 500 users.

now a year and 25k users later i find my self in a bind, i have improved the original code, made all the necessary security improvements and what not and i am ready to launch a 2.0 version.

the problem is this the passwords are stored in mysql in plain text. after i launch the 2.0 version the passwords will be salted and sha256’d. the problem is how do i update the existing records so that i can slat and encrypt them.

i need to pull each password from mysql run it through a script and save them back to the database again. what would be the best way to do that?

thanks in advance.

  • 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-06-08T18:14:49+00:00Added an answer on June 8, 2026 at 6:14 pm

    First off, try all of this stuff on a development machine before you do it in production, and backup your database before you do it in production as well. Migration scripts like this are the single easiest way to lose data.

    1) Create a field in your database (of type ENUM) that states what type of encryption the password field is. Put the default value as ‘unencrypted’

    If you don’t have this, and the update script fails for some reason, you will be left with a half-hashed database.

    How to do that:

    ALTER TABLE application.users
     ADD password_type ENUM('unencrypted', 'SHA256') NOT NULL;
    

    2) Make a php script that looks for 1 unencrypted password, and hashs/salts/stores it.

    <?php
    
    mysql_connect("hostname", "user", "pass") or die(mysql_error());
    mysql_select_db("application") or die(mysql_error());
    
    // Get all the data from the "example" table
    $result = mysql_query("SELECT * FROM users WHERE password_type = 'unencrypted'")
    or die(mysql_error());
    
    // keeps getting the next row until there are no more to get
    $row = mysql_fetch_array( $result );
    
    $pw = $row['password'];
    $id = $row['user_id_num'];
    $id = (int) $id;
    
    $hashed_password = hash("sha256", $pw);
    
    mysql_query("UPDATE users SET password_type = 'SHA256' AND SET password = '$hashed_password' WHERE user_id_num = $id")
    or die(mysql_error());
    
    
    ?>
    

    3) Change that script to do, say, 100 at a time.

    4) Fire off the script with the linux tool cron every minute. Leave it until the whole database is hashed.

    Note that I’ve made some assumptions about the names of stuff in your database.

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

Sidebar

Related Questions

I am learning to work with PHP and have a simple problem. <?php ini_set('display_errors',
So I feel like a serious rookie right now, but I have a problem
I have problem with show or hide form in Window Form Application. I start
I am programmer rookie, and I have to create outlook 2007 add-in. I should
I am learning Java and have a pretty basic problem. I am indexing some
I have problem with Activities navigation, searching works good. Activities hierarchy looks like that:
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem with some JS virus on all of my websites. They're on
I have two dumb/rookie questions. My problem is, I have NO idea where to
Rookie question: I have been experiencing a minor bug in my mvc2 application. I

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.