mysql - Php 5.5 hash API and hashing plain text passwords already in a database -


I have found a solution to the problem referred below, which can help people in using PHP PDO. I tested it and it works, but I'm not sure whether this is clean code or best. No improvement is welcome.

There is a basic problem here for reference:

I haveh The password is already in a MySQL database. I can already use a new password using the HP 5.5 hashing API, but I want to know whether there is any way to get all the old plain text passwords and convert them into a bereavement hash. I am now thinking of copying the password into a new line called 'hash' and checking that they have copied them correctly, they have turned them into hash. I'm not sure how to copy the password line and rename it in the same table, or how to haveh how to do it the most efficiently.

Any insights will be appreciated.

Here's the solution:

   Set to setFetchMode (PDO :: FETCH_ASSOC); // $ hash variable set for a row related to hash (from the database) ($ row = $ stmt-> Get (PDF :: FETCH_ASSOC)) {$ line ['Hush']; $ Hash = $ line ['hash']; } // Update the hash line with the new hash data (note: Before you run the script, make sure that you have copied all plain text passwords in the hash row in the database. $ Newhash = password_hash ($ hash, PASSWORD_DEFAULT); $ sql = "UPDATE securesavegames SET hash = '$ newhash' WHERE id = $ x"; // create bid $ stm = $ dbh- & gt; create ($ sql); // execute $ query- $ stm- & gt; Do (); // A message says that UPDATE successful resonance $ stm-> rowCount (). "Record successfully updated"; // $ Add so that the hash for the next 'id' will be updated, then continue the loop. $ X ++;} $ dbh = null ;;>  

If your password is in plain text, just pass them through the hash and you will be set.

Any query Your update is not easy, because password_hash is a PHP function. You have to get the value and then loop through them will have Pared statement very much with this help They are.

  $ sql = 'Select record_ID, password from table'; $ Res = $ mysqli-> Query ($ sql); $ Sql ​​= 'Update table SET password =? WHERE record_id =? '; $ Prep = $ mysqli- & gt; Ready ($ sql); $ Ready-> Dam_param ('c', $ pass, $ record); While ($ line = $ res-> fetch_assoc ()) {$ pass = password_hash ($ line ['password']); $ Record = $ line ['record_id']; $ Prep- & gt; Executed (); }  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -