You cannot convert md5 to sha , but actually your users only use the password when they are about to login , so you can change your script a little to automatically update
// The user is not authticated yet $auth = false; $updated = false; // From your Login form $user = $_POST['user']; $pass = $_POST['pass']; // Check If the username has update password $udated = false; // not update // I gues you always do this $password = $updated ? md5($pass) : sha1($pass); // Do the autentication // Slect from Database // Check the data // Set auth $auth = true; // Then chage the password if ($auth == true && !$updated) { $newpassword = sha1($pass); // Connect to DB // Update the Password // Set Status to Updated in DB $udated = true; } // Better Approch if ($auth == true && !$updated) { $newpassword = password_hash($password, PASSWORD_BCRYPT); // Connect to DB // Update the Password // Set Status to Updated in DB $updated = true; }
I used password_hash , which has a better approach, because it uses BCRYPT , which is the best hash algorithm. Additional information about password_compat
Baba source share